yaml-validator
yaml-validator copied to clipboard
Errored function is called when validation is ok
Expected behaviour
Errored function is called when an error occurs.
Actual behaviour
Writing Unit Tests (running on Jenkins with mocha), i override errored function to throw Error instead logging error in console.
But now Report function throw an error: "Total of 0 structure validation error(s)", that is definitely not an error.
I suggest to manage error and logs with options object, so anyone can handle errors and logs by his own (as fallback errored implementation will remain the same) like onWarning property of "options".
This is a simple test set to reproduce issue
const path = require("path");
const YamlValidator = require("yaml-validator");
const options = {
log: false,
structure: false,
onWarning: (err, path) => {
console.log("WARN ERROR", path, err);
},
writeJson: false
};
const validator = new YamlValidator(options);
validator.errored = err => {
throw new Error(err);
};
describe("validate yaml file", function() {
it("Should validate gateway.config", done => {
let file = [path.join(__dirname, "./../config/gateway.config.yml")];
validator.validate(file);
validator.report();
done();
});
it("Should validate system.config", done => {
let file = [path.join(__dirname, "./../config/system.config.yml")];
validator.validate(file);
validator.report();
done();
});
});
I will submit a PR as soon as possible if this idea can be interesting.
Versions and environment
- Operating system: Windows 10
- Node.js: 8.10.0
- npm: 5.6.0
- yaml-validator: 2.0.0
Thank you and have some :grapes:.
Sounds good!
@matteoPhre will you be making the PR still?