Skip to content

Commit

Permalink
fix: harden error handling in lib/cli/run.js (#5074)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
stalet and voxpelli authored Mar 26, 2024
1 parent 6f3f45e commit 97dcbb2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ exports.handler = async function (argv) {
try {
await runMocha(mocha, argv);
} catch (err) {
console.error('\n' + (err.stack || `Error: ${err.message || err}`));
console.error('\n Exception during run:', err);
process.exit(1);
}
};
2 changes: 1 addition & 1 deletion test/integration/reporters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('reporters', function () {
return;
}

var pattern = `^Error: invalid or unsupported TAP version: "${invalidTapVersion}"`;
var pattern = `Error: invalid or unsupported TAP version: "${invalidTapVersion}"`;
expect(res, 'to satisfy', {
code: 1,
output: new RegExp(pattern, 'm')
Expand Down

0 comments on commit 97dcbb2

Please sign in to comment.