eslint icon indicating copy to clipboard operation
eslint copied to clipboard

Bug: Configuration that throws an error with an immutable message will crash ESLint with useless error

Open 6XGate opened this issue 2 years ago • 3 comments

Environment

Node version: 14.19.3 npm version: 8.15.0 Local ESLint version: 8.22.0 Global ESLint version: N/A Operating System: Manjaro

What parser are you using?

Default (Espree)

What did you do?

Configuration
class TestError extends Error {
  get message () {
    return `TestError: message`
  }
}

throw new TestError()

No linted code necessary

What did you expect to happen?

ESLint to "crash out" with the TestError's message: TestError: message

What actually happened?

ESLint triggered an unexpected TypeError: Cannot set property message of Error which has only a getter

Participation

  • [ ] I am willing to submit a pull request for this issue.

Additional comments

No response

6XGate avatar Aug 26 '22 14:08 6XGate

Can you create a reproduction case?

ESLint doesn’t execute your code, and the error you’re getting is a runtime error.

nzakas avatar Aug 26 '22 16:08 nzakas

The config code is the reproduction case, it doesn't require any actual code to lint. The .eslintrc.js file is itself throwing an error on purpose.

The issue is; if the error thrown from the config file has an immutable/read-only message property, ESLint causes an new runtime error and swallow the more relevant error thrown by the config file. In this case, the TestError is completely lost and the user is shown the message and stack trace of the irrelevant runtime error.

Hope this helps.

6XGate avatar Aug 26 '22 21:08 6XGate

Oh I see, thanks for explaining. We will take a look.

nzakas avatar Aug 29 '22 17:08 nzakas

@6XGate This seems to be fixed in the new configuration system. I'm not sure if we would want to fix it in the current config system.

@nzakas WDYT?

Old config

Screenshot 2022-11-12 at 7 31 13 AM

New Config

Screenshot 2022-11-12 at 7 31 18 AM

snitin315 avatar Nov 12 '22 02:11 snitin315

@snitin315 thanks for looking into this! As long as it's fixed in the new config system, then I think we are all set and don't need to worry about it for the old config system. @mdjermanovic do you agree?

nzakas avatar Nov 23 '22 21:11 nzakas

I agree as the eslintrc config system is frozen and this doesn't seem like a critical problem.

mdjermanovic avatar Nov 25 '22 23:11 mdjermanovic