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>
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
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. |
|
Yep, and I think they are all waiting on me, I'll try to squeeze them all in this Monday: |
There have been issues where the reported error is "ERROR: null", which is very unhelpful. Here is an analysis of a specific example: mochajs#5048 (comment) Although the trigger for that error was fixed by mochajs#5074, the unhelpfulness of "ERROR: null" was not addressed. To help with debugging, this patch prints the original error when this stage is unexpectedly reached.
* Bugfix: Output stacktrace to support typescript errors. 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" * Update lib/cli/run.js Co-authored-by: Pelle Wessman <pelle@kodfabrik.se> * Fix minor typo. * Update lib/cli/run.js Do not change the original functionality. Co-authored-by: Pelle Wessman <pelle@kodfabrik.se> * Check that the toString method is available on the error. * Opting for a simplified solution * Fix tests --------- Co-authored-by: Pelle Wessman <pelle@kodfabrik.se>
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 prsOverview
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, iatBefore the fix the output was
✖ ERROR: nullDebug 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