Skip to content

Commit

Permalink
Fix: Correct [object Object] output of error.data. (#9561)
Browse files Browse the repository at this point in the history
Stops error.data from being output as [object Object] when the data property
is an object, such as a rule’s options object, by JSON-stringifying error.data.
  • Loading branch information
jrpool authored and ilyavolodin committed Nov 5, 2017
1 parent 51c8cf0 commit b7c5b19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/config/config-validator.js
Expand Up @@ -89,7 +89,9 @@ function validateRuleSchema(id, localOptions, rulesContext) {
if (validateRule) {
validateRule(localOptions);
if (validateRule.errors) {
throw new Error(validateRule.errors.map(error => `\tValue "${error.data}" ${error.message}.\n`).join(""));
throw new Error(validateRule.errors.map(
error => `\tValue ${JSON.stringify(error.data)} ${error.message}.\n`
).join(""));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/config/config-validator.js
Expand Up @@ -352,7 +352,7 @@ describe("Validator", () => {

const fn = validator.validate.bind(null, { rules: { "mock-no-options-rule": [2, "extra"] } }, "tests", linter.rules, linter.environments);

assert.throws(fn, "tests:\n\tConfiguration for rule \"mock-no-options-rule\" is invalid:\n\tValue \"extra\" should NOT have more than 0 items.\n");
assert.throws(fn, "tests:\n\tConfiguration for rule \"mock-no-options-rule\" is invalid:\n\tValue [\"extra\"] should NOT have more than 0 items.\n");
});
});

Expand Down Expand Up @@ -458,7 +458,7 @@ describe("Validator", () => {
it("should throw for too many configuration values", () => {
const fn = validator.validateRuleOptions.bind(null, "mock-rule", [2, "first", "second"], "tests", linter.rules);

assert.throws(fn, "tests:\n\tConfiguration for rule \"mock-rule\" is invalid:\n\tValue \"first,second\" should NOT have more than 1 items.\n");
assert.throws(fn, "tests:\n\tConfiguration for rule \"mock-rule\" is invalid:\n\tValue [\"first\",\"second\"] should NOT have more than 1 items.\n");
});

});
Expand Down

0 comments on commit b7c5b19

Please sign in to comment.