errors: disp ver on fatal except that causes exit

Display Node.js version at the end of stacktraces
on fatal exception that causes exit.
Easier for debugging so you don't have
to ask "what node version are you on?",
it is directly in the error the user
copy/paste from when asking for help.

Fixes: https://github.com/nodejs/node/issues/29731

PR-URL: https://github.com/nodejs/node/pull/38332
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Divlo 2021-09-02 01:59:45 +02:00 committed by Michael Dawson
parent 33b5107d13
commit 59d3d542d6
57 changed files with 165 additions and 12 deletions

View File

@ -605,6 +605,13 @@ added: v0.8.0
Silence deprecation warnings.
### `--no-extra-info-on-fatal-exception`
<!-- YAML
added: REPLACEME
-->
Hide extra information on fatal exception that causes exit.
### `--no-force-async-hooks-checks`
<!-- YAML
added: v9.0.0
@ -1423,6 +1430,7 @@ Node.js options that are allowed are:
* `--napi-modules`
* `--no-deprecation`
* `--no-experimental-repl-await`
* `--no-extra-info-on-fatal-exception`
* `--no-force-async-hooks-checks`
* `--no-warnings`
* `--node-memory-debug`

View File

@ -273,6 +273,9 @@ It is kept for compatibility.
.It Fl -no-deprecation
Silence deprecation warnings.
.
.It Fl -no-extra-info-on-fatal-exception
Hide extra information on fatal exception that causes exit.
.
.It Fl -no-force-async-hooks-checks
Disable runtime checks for `async_hooks`.
These will still be enabled dynamically when `async_hooks` is enabled.

View File

@ -414,6 +414,10 @@ static void ReportFatalException(Environment* env,
}
}
if (env->options()->extra_info_on_fatal_exception) {
FPrintF(stderr, "\nNode.js %s\n", NODE_VERSION);
}
fflush(stderr);
}

View File

@ -511,6 +511,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"show stack traces on process warnings",
&EnvironmentOptions::trace_warnings,
kAllowedInEnvironment);
AddOption("--extra-info-on-fatal-exception",
"hide extra information on fatal exception that causes exit",
&EnvironmentOptions::extra_info_on_fatal_exception,
kAllowedInEnvironment,
true);
AddOption("--unhandled-rejections",
"define unhandled rejections behavior. Options are 'strict' "
"(always raise an error), 'throw' (raise an error unless "

View File

@ -150,6 +150,7 @@ class EnvironmentOptions : public Options {
bool trace_tls = false;
bool trace_uncaught = false;
bool trace_warnings = false;
bool extra_info_on_fatal_exception = true;
std::string unhandled_rejections;
std::string userland_loader;
bool verify_base_objects =

View File

@ -32,3 +32,5 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
expected: { bar: true },
operator: 'throws'
}
Node.js *

View File

@ -12,3 +12,5 @@ RangeError: Invalid input
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -11,3 +11,5 @@ AggregateError: original
at node:internal/main/run_main_module:*:* {
code: 'ERR0'
}
Node.js *

View File

@ -20,3 +20,5 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
expected: 2,
operator: 'strictEqual'
}
Node.js *

Binary file not shown.

View File

@ -5,3 +5,5 @@ await async () => 0;
SyntaxError: Unexpected reserved word
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
at async link (node:internal/modules/esm/module_job:*:*)
Node.js *

View File

@ -7,3 +7,5 @@ SyntaxError: The requested module '../fixtures/es-module-loaders/module-named-ex
at async Loader.import (node:internal/modules/esm/loader:*:*)
at async Object.loadESM (node:internal/process/esm_loader:*:*)
at async handleMainPromise (node:internal/modules/run_main:*:*)
Node.js *

View File

@ -7,3 +7,5 @@ SyntaxError: The requested module './module-named-exports.mjs' does not provide
at async Loader.import (node:internal/modules/esm/loader:*:*)
at async Object.loadESM (node:internal/process/esm_loader:*:*)
at async handleMainPromise (node:internal/modules/run_main:*:*)
Node.js *

View File

@ -4,3 +4,5 @@ await async () => 0;
SyntaxError: Malformed arrow function parameter list
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
Node.js *

View File

@ -16,3 +16,5 @@ Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' imported from *
at Object.loadESM (node:internal/process/esm_loader:*:*) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js *

View File

@ -14,3 +14,5 @@ Did you mean to import some_module/obj.js?
at link (node:internal/modules/esm/module_job:*:*) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js *

View File

@ -18,3 +18,5 @@ Did you mean to import ./test/common/fixtures.js?
at Object.loadESM (node:internal/process/esm_loader:*:*) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js *

View File

@ -7,3 +7,5 @@ await async () => 0;
SyntaxError: Malformed arrow function parameter list
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
at async link (node:internal/modules/esm/module_job:*:*)
Node.js *

View File

@ -10,6 +10,8 @@ SyntaxError: Strict mode code may not include a with statement
at [eval]-wrapper:*:*
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*
Node.js *
42
42
[eval]:1
@ -25,6 +27,8 @@ Error: hello
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*
Node.js *
[eval]:1
throw new Error("hello")
^
@ -37,6 +41,8 @@ Error: hello
at [eval]-wrapper:*:*
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*
Node.js *
100
[eval]:1
var x = 100; y = x;
@ -51,15 +57,21 @@ ReferenceError: y is not defined
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*
[eval]:1
var ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *
[eval]:1
var ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *
[eval]:1
var ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *
done

View File

@ -18,3 +18,5 @@ Emitted 'error' event at:
at Module._compile (node:internal/modules/cjs/loader:*:*)
[... lines matching original stack trace ...]
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -13,3 +13,5 @@ Error
Emitted 'error' event at:
at *events_unhandled_error_nexttick.js:*:*
at processTicksAndRejections (node:internal/process/task_queues:*:*)
Node.js *

View File

@ -15,3 +15,5 @@ Emitted 'error' event at:
at Module._compile (node:internal/modules/cjs/loader:*:*)
[... lines matching original stack trace ...]
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -15,3 +15,5 @@ Emitted 'error' event on Foo instance at:
at Module._compile (node:internal/modules/cjs/loader:*:*)
[... lines matching original stack trace ...]
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -33,3 +33,5 @@ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
expected: null,
operator: 'ifError'
}
Node.js *

View File

@ -16,3 +16,5 @@ Please open an issue with this stack trace at https://github.com/nodejs/node/iss
at * {
code: 'ERR_INTERNAL_ASSERTION'
}
Node.js *

View File

@ -17,3 +17,5 @@ Please open an issue with this stack trace at https://github.com/nodejs/node/iss
at * {
code: 'ERR_INTERNAL_ASSERTION'
}
Node.js *

View File

@ -5,3 +5,5 @@
ReferenceError: undefined_reference_error_maker is not defined
at *test*message*nexttick_throw.js:*:*
at processTicksAndRejections (node:internal/process/task_queues:*:*)
Node.js *

View File

@ -11,3 +11,5 @@ Error: One
at *
at *
at *
Node.js *

View File

@ -24,3 +24,5 @@ Error: an error!
at Module.load (node:internal/modules/cjs/loader:*)
at Function.Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)
Node.js *

View File

@ -28,3 +28,5 @@ Error: an error!
at Module.load (node:internal/modules/cjs/loader:*)
at Function.Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)
Node.js *

View File

@ -13,3 +13,5 @@ Error: an error!
at Module.load (node:internal/modules/cjs/loader:*)
at Function.Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)
Node.js *

View File

@ -13,3 +13,5 @@ ReferenceError: alert is not defined
at require (node:internal/modules/cjs/helpers:*
at Object.<anonymous> (*source_map_reference_error_tabs.js:*
at Module._compile (node:internal/modules/cjs/loader:*
Node.js *

View File

@ -13,3 +13,5 @@ Error: an exception
at require (node:internal/modules/cjs/helpers:*)
at Object.<anonymous> (*source_map_throw_first_tick.js:5:1)
at Module._compile (node:internal/modules/cjs/loader:*)
Node.js *

View File

@ -13,3 +13,5 @@ Error: an error
at require (node:internal/modules/cjs/helpers:*
at Object.<anonymous> (*source_map_throw_icu.js:*
at Module._compile (node:internal/modules/cjs/loader:*
Node.js *

View File

@ -6,3 +6,5 @@ Error: goodbye
at Hello *uglify-throw-original.js:5:9*
at *uglify-throw-original.js:9:3*
at processImmediate (node:internal/timers:*)
Node.js *

View File

@ -4,3 +4,5 @@ JSON.stringify(array);
^
[RangeError: Maximum call stack size exceeded]
Node.js *

View File

@ -14,6 +14,8 @@ SyntaxError: Strict mode code may not include a with statement
at Socket.<anonymous> (node:internal/process/execution:*:*)
at Socket.emit (node:events:*:*)
at endReadableNT (node:internal/streams/readable:*:*)
Node.js *
42
42
[stdin]:1
@ -31,6 +33,8 @@ Error: hello
at Socket.<anonymous> (node:internal/process/execution:*:*)
at Socket.emit (node:events:*:*)
at endReadableNT (node:internal/streams/readable:*:*)
Node.js *
[stdin]:1
throw new Error("hello")
^
@ -46,6 +50,8 @@ Error: hello
at Socket.<anonymous> (node:internal/process/execution:*:*)
at Socket.emit (node:events:*:*)
at endReadableNT (node:internal/streams/readable:*:*)
Node.js *
100
[stdin]:1
let x = 100; y = x;
@ -63,15 +69,21 @@ ReferenceError: y is not defined
at Socket.emit (node:events:*:*)
at endReadableNT (node:internal/streams/readable:*:*)
[stdin]:1
let ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *
[stdin]:1
let ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *
[stdin]:1
let ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *
done

View File

@ -0,0 +1,6 @@
// Flags: --no-extra-info-on-fatal-exception
'use strict';
require('../common');
throw new Error('foo');

View File

@ -0,0 +1,12 @@
*:6
throw new Error('foo');
^
Error: foo
at Object.<anonymous> (*:6:7)
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*

View File

@ -2,3 +2,5 @@
throw ({ name: 'MyCustomError', message: 'This is a custom message' });
^
{ name: 'MyCustomError', message: 'This is a custom message' }
Node.js *

View File

@ -4,3 +4,5 @@ throw { // eslint-disable-line no-throw-literal
^
[object Object]
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *

View File

@ -11,3 +11,5 @@ Thrown at:
at Module._load (node:internal/modules/cjs/loader:*:*)
at executeUserEntryPoint (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -3,3 +3,5 @@ before
throw ({ foo: 'bar' });
^
{ foo: 'bar' }
Node.js *

View File

@ -2,3 +2,5 @@
throw ({ foo: 'bar' });
^
{ foo: 'bar' }
Node.js *

View File

@ -4,3 +4,5 @@ throw null;
^
null
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *

View File

@ -11,3 +11,5 @@ Thrown at:
at Module._load (node:internal/modules/cjs/loader:*:*)
at executeUserEntryPoint (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -4,3 +4,5 @@ throw undefined;
^
undefined
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *

View File

@ -11,3 +11,5 @@ Thrown at:
at Module._load (node:internal/modules/cjs/loader:*:*)
at executeUserEntryPoint (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -5,3 +5,5 @@ ReferenceError: undefined_reference_error_maker is not defined
at Timeout._onTimeout (*test*message*timeout_throw.js:*:*)
at listOnTimeout (node:internal/timers:*:*)
at processTimers (node:internal/timers:*:*)
Node.js *

View File

@ -14,3 +14,5 @@ ReferenceError: foo is not defined
at Module.load (node:internal/modules/cjs/loader:*)
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
Node.js *

View File

@ -29,3 +29,5 @@ Error: spooky!
at Function.Module._load (node:internal/modules/cjs/loader:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*)
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -27,3 +27,5 @@ SyntaxError: Unexpected number
at Function.Module._load (node:internal/modules/cjs/loader:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*)
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -15,3 +15,5 @@ Error: boo!
at Function.Module._load (node:internal/modules/cjs/loader:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*)
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -15,3 +15,5 @@ SyntaxError: Unexpected number
at Function.Module._load (node:internal/modules/cjs/loader:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*)
at node:internal/main/run_main_module:*:*
Node.js *

View File

@ -26,6 +26,7 @@ expect('--no-deprecation', 'B\n');
expect('--no-warnings', 'B\n');
expect('--no_warnings', 'B\n');
expect('--trace-warnings', 'B\n');
expect('--no-extra-info-on-fatal-exception', 'B\n');
expect('--redirect-warnings=_', 'B\n');
expect('--trace-deprecation', 'B\n');
expect('--trace-sync-io', 'B\n');

View File

@ -77,6 +77,5 @@ errExec('throws_error6.js', common.mustCall((err, stdout, stderr) => {
// Object that throws in toString() doesn't print garbage
errExec('throws_error7.js', common.mustCall((err, stdout, stderr) => {
assert.match(stderr,
/throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/);
assert.match(stderr, /throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n\r?\nNode\.js \S+\r?\n$/);
}));

View File

@ -12,3 +12,5 @@ TypeError: foobar
*[90m at *[39m {
bla: *[33mtrue*[39m
}
Node.js *