From dd882108c97a017211511c378570460e2d3d1bcd Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Sun, 27 Apr 2025 22:24:48 +0200 Subject: [PATCH] fix: print error when internal cli error happens 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. --- lib/cli/cli.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 6229335d85..b4371119b4 100755 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -61,6 +61,7 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => { debug('caught error sometime before command handler: %O', err); yargs.showHelp(); console.error(`\n${symbols.error} ${pc.red('ERROR:')} ${msg}`); + console.error(err); process.exit(1); }) .help('help', 'Show usage information & exit')