From 5ab282fabf48776ad4f6779629592039dbb5fb20 Mon Sep 17 00:00:00 2001 From: Victor Hom Date: Tue, 1 Aug 2017 03:52:12 -0400 Subject: [PATCH] Fix: Print error message in bin/eslint.js (fixes #9011) (#9041) --- bin/eslint.js | 2 ++ tests/bin/eslint.js | 17 ++++++++++++++--- tests/fixtures/bin/.eslintrc.yml | 5 +++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/bin/.eslintrc.yml diff --git a/bin/eslint.js b/bin/eslint.js index 7c05ad3b6e6..10a7f73dae1 100755 --- a/bin/eslint.js +++ b/bin/eslint.js @@ -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); } diff --git a/tests/bin/eslint.js b/tests/bin/eslint.js index 1c45aa4298b..39be27fb032 100644 --- a/tests/bin/eslint.js +++ b/tests/bin/eslint.js @@ -263,7 +263,7 @@ 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 => { @@ -271,9 +271,20 @@ describe("bin/eslint.js", () => { 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]); diff --git a/tests/fixtures/bin/.eslintrc.yml b/tests/fixtures/bin/.eslintrc.yml new file mode 100644 index 00000000000..e1a07bb4014 --- /dev/null +++ b/tests/fixtures/bin/.eslintrc.yml @@ -0,0 +1,5 @@ +# intentionally invalid YML +rules: + semi: error +yoda: error + quotes: error