Skip to content

Commit

Permalink
Fix: Print error message in bin/eslint.js (fixes #9011) (#9041)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorHom authored and not-an-aardvark committed Aug 1, 2017
1 parent 50e3cf3 commit 5ab282f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bin/eslint.js
Expand Up @@ -47,6 +47,8 @@ process.once("uncaughtException", err => {
console.error("\nOops! Something went wrong! :(");
console.error(`\n${template(err.messageData || {})}`);
} else {

console.error(err.message);
console.error(err.stack);
}

Expand Down
17 changes: 14 additions & 3 deletions tests/bin/eslint.js
Expand Up @@ -263,17 +263,28 @@ describe("bin/eslint.js", () => {
});

describe("handling crashes", () => {
it("prints the error message exactly once to stderr in the event of a crash", () => {
it("prints the error message to stderr in the event of a crash", () => {
const child = runESLint(["--rule=no-restricted-syntax:[error, 'Invalid Selector [[[']", "Makefile.js"]);
const exitCodeAssertion = assertExitCode(child, 1);
const outputAssertion = getOutput(child).then(output => {
const expectedSubstring = "Syntax error in selector";

assert.strictEqual(output.stdout, "");
assert.include(output.stderr, expectedSubstring);
});

// The message should appear exactly once in stderr
assert.strictEqual(output.stderr.indexOf(expectedSubstring), output.stderr.lastIndexOf(expectedSubstring));
return Promise.all([exitCodeAssertion, outputAssertion]);
});

it("prints the error message pointing to line of code", () => {
const invalidConfig = `${__dirname}/../fixtures/bin/.eslintrc.yml`;
const child = runESLint(["--no-ignore", invalidConfig]);
const exitCodeAssertion = assertExitCode(child, 1);
const outputAssertion = getOutput(child).then(output => {
const expectedSubstring = "Error: bad indentation of a mapping entry at line";

assert.strictEqual(output.stdout, "");
assert.include(output.stderr, expectedSubstring);
});

return Promise.all([exitCodeAssertion, outputAssertion]);
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/bin/.eslintrc.yml
@@ -0,0 +1,5 @@
# intentionally invalid YML
rules:
semi: error
yoda: error
quotes: error

0 comments on commit 5ab282f

Please sign in to comment.