Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some error messages are missing in v4.3.0 #9011

Closed
not-an-aardvark opened this issue Jul 26, 2017 · 3 comments · Fixed by #9044
Closed

Some error messages are missing in v4.3.0 #9011

not-an-aardvark opened this issue Jul 26, 2017 · 3 comments · Fixed by #9044
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features regression Something broke

Comments

@not-an-aardvark
Copy link
Member

Tell us about your environment

  • ESLint Version: 4.3.0
  • Node Version: 8.2.1
  • npm Version: 5.3.0

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

Configuration
# intentionally invalid YML

rules:
  semi: error
yoda: error
  quotes: error

What did you do? Please include the actual source code causing the issue.

a

What did you expect to happen?

I expected to receive a useful error message indicating that the configuration was invalid.

What actually happened? Please include the actual, raw output from ESLint.

Error
    at generateError (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:165:10)
    at throwError (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:171:9)
    at readBlockMapping (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1080:7)
    at composeNode (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1332:12)
    at readDocument (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1492:3)
    at loadDocuments (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1548:5)
    at load (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1569:19)
    at Object.safeLoad (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1591:10)
    at loadYAMLConfigFile (/path/to/eslint/lib/config/config-file.js:97:21)
    at loadConfigFile (/path/to/eslint/lib/config/config-file.js:233:22)

In 4.2.0, the error also included a message:

Cannot read config file: /path/to/sandbox/.eslintrc.yml
Error: bad indentation of a mapping entry at line 6, column 9:
      quotes: error
            ^
Error
    at generateError (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:165:10)
    at throwError (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:171:9)
    at readBlockMapping (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1080:7)
    at composeNode (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1332:12)
    at readDocument (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1492:3)
    at loadDocuments (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1548:5)
    at load (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1569:19)
    at Object.safeLoad (/path/to/eslint/node_modules/js-yaml/lib/js-yaml/loader.js:1591:10)
    at loadYAMLConfigFile (/path/to/eslint/lib/config/config-file.js:97:21)
    at loadConfigFile (/path/to/eslint/lib/config/config-file.js:233:22)

This is a regression caused by a5fd101. To avoid duplicated error messages, we stopped printing error.message for uncaught exceptions since the message is usually already contained in error.stack. However, there are several places where we mutate error.message after creating an error in order to add additional information, so the information is now getting lost.

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features regression Something broke labels Jul 26, 2017
VictorHom added a commit to VictorHom/eslint that referenced this issue Jul 29, 2017
@VictorHom
Copy link
Member

VictorHom commented Jul 29, 2017

@not-an-aardvark

I am getting the same error as you indicated from 4.2.0. My configuration is the following:

eslint: v4.3.0
node: v6.9.4
npm: 3.10.10

However, I do see the same(lack of) error when I switched to node 8.2.1

screen shot 2017-07-29 at 3 23 50 pm

screen shot 2017-07-29 at 3 24 03 pm

@not-an-aardvark
Copy link
Member Author

Hmm, this is more complicated than I thought. It seems like Node has a strange behavior with error stacks -- modifying the message will also modify the stack, but only if the stack has never been previously accessed.

const err = new Error('original message');
err.message = 'updated message';
console.log(err.stack);

// => Error: updated message
//           (followed by stack trace)
const err = new Error('original message');

// access the stack property
err.stack;

err.message = 'updated message';
console.log(err.stack);

// => Error: original message
//           (followed by stack trace)

There doesn't appear to be a getter on err.stack, so it's probably some magical internal behavior in V8.

This applies in both Node 8.2.1 and Node 6.11.1. However, the difference in behavior between the two Node versions is probably related to nodeca/js-yaml#351, which might also be caused by weird Error.stack behavior.

@not-an-aardvark
Copy link
Member Author

I made a partial fix upstream in nodeca/js-yaml#360. This will make sure at least some error message is present, rather than having the stack be empty. However, the stack still won't update after the message property is reassigned, so the stack will only contain the error message from js-yaml as a result of that fix, and not the additional information from ESLint.

The root cause of the issue is this commit in V8, which was first introduced in Node 7. Stack traces are evaluated lazily in Node (they are only created the first time the stack property is accessed on an error object). As a result, modifying the message property of an error sometimes causes the stack to change, but only if the stack property has never been accessed. js-yaml uses Error.captureStackTrace internally, and starting in Node 7 Error.captureStackTrace will eagerly compute the stack trace.

The commit in V8 was reverted a few weeks ago here, but it might take awhile before that lands in a Node release. Also, I'm not sure we should rely on this behavior, since it seems risky to rely on whether the stack property of an error is accessed anywhere.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features regression Something broke
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants