es-check icon indicating copy to clipboard operation
es-check copied to clipboard

False positives from ErrorCause feature check

Open kitschpatrol opened this issue 10 months ago • 1 comments

Thanks for this project!

Even though new Error("message") syntax has been valid since ES3, es-check with the --checkFeatures flag seems to mark this as requiring > ES13 regardless of whether a cause option is passed to the Error constructor.

For example:

Given file:

// error-without-cause.js
throw new Error('Something went wrong')

We get this incorrect error from es-check:

$ es-check es10 ./error-without-cause.js --checkFeatures
...`Error: Unsupported features detected: ErrorCause. These require a higher ES version than 10.`

I took a quick look at the feature description code, and found that its astInfo has a hasOptionsCause value which I would assume might match against something in the AST:

  ErrorCause: {
    minVersion: 13,
    example: 'new Error("...", { cause: e })',
    astInfo: {
      nodeType: 'NewExpression',
      callee: 'Error',
      hasOptionsCause: true,
    },
  },

...but I couldn't find a code path in es-check where this is ever actually verified, and never saw such a key in raw acorn output, though maybe I'm missing something!

kitschpatrol avatar Mar 01 '25 23:03 kitschpatrol

Thanks for your comment @kitschpatrol! I will add this to a batch fix pretty soon if I can reproduce and test. 🙏

yowainwright avatar Mar 02 '25 00:03 yowainwright

@kitschpatrol I think we may have implemented a fix for this. Install the beta release if you'd like to try it out. 🙌

Thanks for pointing this issue out and your patience!

yowainwright avatar Apr 28 '25 15:04 yowainwright

Hey thank you so much for looking into this and for the recent updates. FWIW I'm still seeing false positives with 9.1.1. (And seeing the same with the older next version 9.1.0-0.)

To reproduce:

echo "throw new Error('Something went wrong')" > test.js
npx [email protected] es10 ./test.js --checkFeatures

Throws:

/Users/mika/.npm/_npx/6d33ea6b84e4298d/node_modules/es-check/detectFeatures.js:148
    const error = new Error(
                  ^

Error: Unsupported features detected: ErrorCause. These require a higher ES version than 10.
    at detectFeatures (/Users/mika/.npm/_npx/6d33ea6b84e4298d/node_modules/es-check/detectFeatures.js:148:19)
    at /Users/mika/.npm/_npx/6d33ea6b84e4298d/node_modules/es-check/index.js:534:54
    at Array.forEach (<anonymous>)
    at runChecks (/Users/mika/.npm/_npx/6d33ea6b84e4298d/node_modules/es-check/index.js:509:19)
    at Command.<anonymous> (/Users/mika/.npm/_npx/6d33ea6b84e4298d/node_modules/es-check/index.js:323:14) {
  type: 'ES-Check',
  features: [ 'ErrorCause' ],
  ecmaVersion: 10
}

Node.js v23.11.0

kitschpatrol avatar Apr 30 '25 18:04 kitschpatrol

Re-opened. Thanks for the feedback! 🙇

yowainwright avatar Apr 30 '25 19:04 yowainwright

@kitschpatrol can you check if 9.1.2-0 fixed this issue? Thanks for your patience!

yowainwright avatar May 02 '25 05:05 yowainwright

It's a fix, thanks!

echo "throw new Error('Something went wrong')" > test.js
npx [email protected] es10 ./test.js --checkFeatures
info: ES-Check: there were no ES version matching errors!  🎉

kitschpatrol avatar May 02 '25 15:05 kitschpatrol