Skip to content

Commit

Permalink
Fix: Remove duplicate error message on crash (fixes #8964) (#10865)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas authored and aladdin-add committed Sep 20, 2018
1 parent 4eb9a49 commit 9d52541
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion bin/eslint.js
Expand Up @@ -48,7 +48,6 @@ process.once("uncaughtException", err => {
console.error(`\nESLint: ${pkg.version}.\n${template(err.messageData || {})}`);
} else {

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

Expand Down
18 changes: 17 additions & 1 deletion tests/bin/eslint.js
Expand Up @@ -333,12 +333,28 @@ describe("bin/eslint.js", () => {
return Promise.all([exitCodeAssertion, outputAssertion]);
});

it("prints the error message exactly once to stderr in the event of a crash", () => {
const child = runESLint(["--rule=no-restricted-syntax:[error, 'Invalid Selector [[[']", "Makefile.js"]);
const exitCodeAssertion = assertExitCode(child, 2);
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, 2);
const outputAssertion = getOutput(child).then(output => {
const expectedSubstring = "Error: bad indentation of a mapping entry at line";
const expectedSubstring = ": bad indentation of a mapping entry at line";

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

0 comments on commit 9d52541

Please sign in to comment.