-
-
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
🐛 Bug: Errorhandling fails when node:module registered errors are thrown #5085
Comments
And as a sidenote - something must have changed in the latest versions - since I am now discovering this issue in multiple projects where i am using ts-node along with mocha. |
I did a little digging. From https://github.com/stalet/mocha-typescript-testproject?tab=readme-ov-file#debugging-test:
That's: Line 372 in 2b98521
Putting a breakpoint in there (
...so, the issue is not that the thrown error is null. It's that it's an object from a loader/worker thread that comes in with an undefined prototype. Which can't be converted/coerced to a string the way the code is trying to because it doesn't have a nodejs/node#48207 is when those objects were fixed to be printable in a debugger. Adding
https://nodejs.org/api/module.html#moduleregisterspecifier-parenturl-options -> https://nodejs.org/api/module.html#customization-hooks has context for what's going on. https://nodejs.org/api/util.html#custom-inspection-functions-on-objects specifically shows how turn these objects into a string. const util = require('node:util');
const stringified = util.inspect(err);
console.log(stringified);
'test/index.test.ts(5,1): error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
test/index.test.ts(6,5): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
test/index.test.ts(9,44): error TS2322: Type 'string' is not assignable to type 'number'.
' We can therefore narrow down that the issue is that errors thrown within a |
Bug Report Checklist
faq
label, but none matched my issue.Expected
When running a test that throws a null error i expect to get information about what happened and the errorhandler to give useful output.
Actual
When an null error is thrown when running the tests the output from the mocha script is the program option list and a line:
✖ ERROR: null
Minimal, Reproducible Example
I created a PR for this error - thinking this was only applicable for Typescript errors, but as stated in the PR: all null errors it will cause this to happen.
Nevertheless, the example created for the original PR shows the error:
https://github.com/stalet/mocha-typescript-testproject
Versions
10.2.0
Additional Info
This error was reported as part of PR #5074 - but since it's not just applicable for Typescript errors the PR was closed - and I am opening this issue instead.
The text was updated successfully, but these errors were encountered: