yaml-validator icon indicating copy to clipboard operation
yaml-validator copied to clipboard

Errored function is called when validation is ok

Open matteoPhre opened this issue 5 years ago • 2 comments

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:.

matteoPhre avatar Jan 18 '19 15:01 matteoPhre

Sounds good!

paazmaya avatar Jan 21 '19 21:01 paazmaya

@matteoPhre will you be making the PR still?

paazmaya avatar Sep 13 '19 10:09 paazmaya