-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: harden error handling in lib/cli/run.js
#5074
fix: harden error handling in lib/cli/run.js
#5074
Conversation
Can you provide a reproduction? Sounds odd that it would swallow all TypeScript errors currently Other PR:s related to error reporting are eg: |
I have created a small project that reproduces the error here: https://github.com/stalet/mocha-typescript-testproject |
Before this patch the errorhandling would fail with the error: "ERROR: null". Debug showed that the error "caught error sometime before command handler: TypeError: Cannot convert object to primitive value"
ecba5cd
to
77934c1
Compare
It's a general thing with errors not related to Typescript console.error('\n' + (err.stack || `Error: ${err.message || err}`)); the above line from mocha fail if I throw null as an error try {
throw null;
} catch (err) {
console.error('\n' + (err.stack || `Error: ${err.message || err}`));
} the error will be
|
👀
See
Closing this PR so it doesn't show up on our review queue. But if it is determined in an issue that we can take this in, we'd be happy to re-open and review. Thanks for sending! tl;dr: please file an issue so we can discuss there 🙂. |
Co-authored-by: Pelle Wessman <pelle@kodfabrik.se>
Do not change the original functionality. Co-authored-by: Pelle Wessman <pelle@kodfabrik.se>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes to handle the node:module
case of errors that don't have a toString()
method. Please let me know if I've gone down the totally wrong track though!
After these changes I have verified the in the testproject i get the following output instead of
Which was the intention. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
now we only need to support AggregateError
and Error cause
and it will be perfect reporting
I think they have separated issues
Yep, and I think they are all waiting on me, I'll try to squeeze them all in this Monday: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Included in v10.4.0 🎉 |
Before this patch the errorhandling would fail with the error: "ERROR: null". Debug showed that the error "caught error sometime before command handler: TypeError: Cannot convert object to primitive value"
PR Checklist
status: accepting prs
Overview
When the error in the runner is a typescript error the current script fails with the error: "TypeError: Cannot convert object to primitive value" - leaving the output as a null value.
It is very hard to see the actuall error. With this change the output will be something like this.
Error: undefined test/testdata.ts(59,14): error TS2739: Type '{ loginId: number; spidId: number; sid: string; amr: never[]; }' is missing the following properties from type 'Identity': sub, nbf, exp, iat
Before the fix the output was
✖ ERROR: null
Debug output contailed this
mocha:cli:cli caught error sometime before command handler: TypeError: Cannot convert object to primitive value mocha:cli:cli at exports.handler (/home/stalet/code/account/min-finn-frontend/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/cli/run.js:372:65) +859ms