From 77934c135bb00fcfa2b4d834d3ff3633392e70a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Tomten?= Date: Mon, 8 Jan 2024 11:44:59 +0100 Subject: [PATCH 1/7] 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" --- lib/cli/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index fbbe510e94..1cb4ecea5a 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -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' + (err.stack || `Error: ${err && err.message}`), err); process.exit(1); } }; From 25bda255192831971134122319729a0feb15b5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Tomten?= Date: Mon, 22 Jan 2024 14:33:11 +0100 Subject: [PATCH 2/7] Update lib/cli/run.js Co-authored-by: Pelle Wessman --- lib/cli/run.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index 1cb4ecea5a..1203e992fd 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -369,7 +369,12 @@ exports.handler = async function (argv) { try { await runMocha(mocha, argv); } catch (err) { - console.error('\n' + (err.stack || `Error: ${err && err.message}`), err); + if (!err) { + console.error('\n Undefined error:`, err); + } else { + console.error('\n' + (err.stack || `Error: ${err.message}`), err); + } + process.exit(1); } }; From d9e64ad992cf9da635dc2e1eb276621fd2208748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Tomten?= Date: Mon, 22 Jan 2024 15:15:19 +0100 Subject: [PATCH 3/7] Fix minor typo. --- lib/cli/run.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index 1203e992fd..91e36b0668 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -370,11 +370,11 @@ exports.handler = async function (argv) { await runMocha(mocha, argv); } catch (err) { if (!err) { - console.error('\n Undefined error:`, err); + console.error('\n Undefined error:', err); } else { console.error('\n' + (err.stack || `Error: ${err.message}`), err); } - + process.exit(1); } }; From 8b7613c55f17a487f5abde6ef92c254c60c5f4ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Tomten?= Date: Fri, 26 Jan 2024 08:45:32 +0100 Subject: [PATCH 4/7] Update lib/cli/run.js Do not change the original functionality. Co-authored-by: Pelle Wessman --- lib/cli/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index 91e36b0668..6eb5ed9a49 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -372,7 +372,7 @@ exports.handler = async function (argv) { if (!err) { console.error('\n Undefined error:', err); } else { - console.error('\n' + (err.stack || `Error: ${err.message}`), err); + console.error('\n' + (err.stack || `Error: ${err.message || err}`)); } process.exit(1); From 3a11deff41d361c33e84901238569d06e1b45286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Tomten?= Date: Thu, 8 Feb 2024 11:12:49 +0100 Subject: [PATCH 5/7] Check that the toString method is available on the error. --- lib/cli/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index 6eb5ed9a49..92908be435 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -369,7 +369,7 @@ exports.handler = async function (argv) { try { await runMocha(mocha, argv); } catch (err) { - if (!err) { + if (!err || !err.toString) { console.error('\n Undefined error:', err); } else { console.error('\n' + (err.stack || `Error: ${err.message || err}`)); From f66505f7aef569516ff6aec8ee79714c1dd66dc8 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Tue, 20 Feb 2024 13:42:11 +0100 Subject: [PATCH 6/7] Opting for a simplified solution --- lib/cli/run.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index 92908be435..66c8cbbb66 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -369,12 +369,7 @@ exports.handler = async function (argv) { try { await runMocha(mocha, argv); } catch (err) { - if (!err || !err.toString) { - console.error('\n Undefined error:', err); - } else { - console.error('\n' + (err.stack || `Error: ${err.message || err}`)); - } - + console.error('\n Exception during run:', err); process.exit(1); } }; From 9a651495dd58b20d91d8c85c45e5030146ca89ba Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Tue, 26 Mar 2024 17:40:53 +0100 Subject: [PATCH 7/7] Fix tests --- test/integration/reporters.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/reporters.spec.js b/test/integration/reporters.spec.js index cdc15b8233..847a0239d3 100644 --- a/test/integration/reporters.spec.js +++ b/test/integration/reporters.spec.js @@ -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')