mocha
mocha copied to clipboard
fix: print error when internal cli error happens (more helpful than ERROR: null)
PR Checklist
- [x] Addresses an existing open issue: fixes #5078 / #5048 / others (the
ERROR: nullpart of it) - [x] That issue was marked as
status: accepting prs - [x] Steps in CONTRIBUTING.md were taken
Overview
There have been issues where the reported error is "ERROR: null", which is very unhelpful. Here is an analysis of a specific example: https://github.com/mochajs/mocha/issues/5048#issuecomment-2833619212
Although the trigger for that error was fixed by #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.
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: mark-wiemer / name: Mark Wiemer (7cda07e4cfc6b0fb81b0e980deeef54501b66b2c)
- :white_check_mark: login: Rob--W / name: Rob Wu (dd882108c97a017211511c378570460e2d3d1bcd)
Switching to draft pending https://github.com/mochajs/mocha/issues/5078#issuecomment-2845231557. We can't review without a reproduction, and it might be that all buggy behavior was already fixed?
Thanks for the PR in the interim though!
Switching to draft pending https://github.com/mochajs/mocha/issues/5078#issuecomment-2845231557. We can't review without a reproduction, and it might be that all buggy behavior was already fixed?
For clarity, this is not about fixing whatever that triggered the error, but about improving the logged diagnostics information when an error (unexpectedly) happens.
While the specific trigger was fixed, it is still possible to end up in this case if some other internal error occurs. If you want to reproduce locally, you could throw an error from https://github.com/mochajs/mocha/blob/abf3dd921544b45c4c09eef8f7c9c3c4481a3d66/lib/cli/run.js#L377
There are probably other ways to trigger this issue, but I haven't looked.
If you are concerned about logging too much information (when an error message is already present), I could add a check to only log the error when the message is null.