From 9d52541b67b9bad6e77c5b62e9a2cb4212d4998a Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 20 Sep 2018 07:04:51 -0700 Subject: [PATCH] Fix: Remove duplicate error message on crash (fixes #8964) (#10865) --- bin/eslint.js | 1 - tests/bin/eslint.js | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bin/eslint.js b/bin/eslint.js index adc07c2e75c..e51121ec6af 100755 --- a/bin/eslint.js +++ b/bin/eslint.js @@ -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); } diff --git a/tests/bin/eslint.js b/tests/bin/eslint.js index 75e7c2c4b7c..7749b12f107 100644 --- a/tests/bin/eslint.js +++ b/tests/bin/eslint.js @@ -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);