Skip to content

Commit 59d3d54

Browse files
theoludwigmhdawson
authored andcommitted
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: #29731 PR-URL: #38332 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 33b5107 commit 59d3d54

File tree

57 files changed

+155
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+155
-2
lines changed

doc/api/cli.md

+8

doc/node.1

+3
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ It is kept for compatibility.
273273
.It Fl -no-deprecation
274274
Silence deprecation warnings.
275275
.
276+
.It Fl -no-extra-info-on-fatal-exception
277+
Hide extra information on fatal exception that causes exit.
278+
.
276279
.It Fl -no-force-async-hooks-checks
277280
Disable runtime checks for `async_hooks`.
278281
These will still be enabled dynamically when `async_hooks` is enabled.

src/node_errors.cc

+4
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ static void ReportFatalException(Environment* env,
414414
}
415415
}
416416

417+
if (env->options()->extra_info_on_fatal_exception) {
418+
FPrintF(stderr, "\nNode.js %s\n", NODE_VERSION);
419+
}
420+
417421
fflush(stderr);
418422
}
419423

src/node_options.cc

+5
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
511511
"show stack traces on process warnings",
512512
&EnvironmentOptions::trace_warnings,
513513
kAllowedInEnvironment);
514+
AddOption("--extra-info-on-fatal-exception",
515+
"hide extra information on fatal exception that causes exit",
516+
&EnvironmentOptions::extra_info_on_fatal_exception,
517+
kAllowedInEnvironment,
518+
true);
514519
AddOption("--unhandled-rejections",
515520
"define unhandled rejections behavior. Options are 'strict' "
516521
"(always raise an error), 'throw' (raise an error unless "

src/node_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class EnvironmentOptions : public Options {
150150
bool trace_tls = false;
151151
bool trace_uncaught = false;
152152
bool trace_warnings = false;
153+
bool extra_info_on_fatal_exception = true;
153154
std::string unhandled_rejections;
154155
std::string userland_loader;
155156
bool verify_base_objects =

test/message/assert_throws_stack.out

+2
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
3232
expected: { bar: true },
3333
operator: 'throws'
3434
}
35+
36+
Node.js *

test/message/core_line_numbers.out

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ RangeError: Invalid input
1212
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
1313
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
1414
at node:internal/main/run_main_module:*:*
15+
16+
Node.js *

test/message/error_aggregateTwoErrors.out

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ AggregateError: original
1111
at node:internal/main/run_main_module:*:* {
1212
code: 'ERR0'
1313
}
14+
15+
Node.js *

test/message/error_exit.out

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
2020
expected: 2,
2121
operator: 'strictEqual'
2222
}
23+
24+
Node.js *

test/message/error_with_nul.out

11 Bytes
Binary file not shown.

test/message/esm_display_syntax_error.out

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ await async () => 0;
55
SyntaxError: Unexpected reserved word
66
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
77
at async link (node:internal/modules/esm/module_job:*:*)
8+
9+
Node.js *

test/message/esm_display_syntax_error_import.out

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ SyntaxError: The requested module '../fixtures/es-module-loaders/module-named-ex
77
at async Loader.import (node:internal/modules/esm/loader:*:*)
88
at async Object.loadESM (node:internal/process/esm_loader:*:*)
99
at async handleMainPromise (node:internal/modules/run_main:*:*)
10+
11+
Node.js *

test/message/esm_display_syntax_error_import_module.out

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ SyntaxError: The requested module './module-named-exports.mjs' does not provide
77
at async Loader.import (node:internal/modules/esm/loader:*:*)
88
at async Object.loadESM (node:internal/process/esm_loader:*:*)
99
at async handleMainPromise (node:internal/modules/run_main:*:*)
10+
11+
Node.js *

test/message/esm_display_syntax_error_module.out

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ await async () => 0;
44

55
SyntaxError: Malformed arrow function parameter list
66
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
7+
8+
Node.js *

test/message/esm_loader_not_found.out

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' imported from *
1616
at Object.loadESM (node:internal/process/esm_loader:*:*) {
1717
code: 'ERR_MODULE_NOT_FOUND'
1818
}
19+
20+
Node.js *

test/message/esm_loader_not_found_cjs_hint_bare.out

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ Did you mean to import some_module/obj.js?
1414
at link (node:internal/modules/esm/module_job:*:*) {
1515
code: 'ERR_MODULE_NOT_FOUND'
1616
}
17+
18+
Node.js *

test/message/esm_loader_not_found_cjs_hint_relative.out

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ Did you mean to import ./test/common/fixtures.js?
1818
at Object.loadESM (node:internal/process/esm_loader:*:*) {
1919
code: 'ERR_MODULE_NOT_FOUND'
2020
}
21+
22+
Node.js *

test/message/esm_loader_syntax_error.out

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ await async () => 0;
77
SyntaxError: Malformed arrow function parameter list
88
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
99
at async link (node:internal/modules/esm/module_job:*:*)
10+
11+
Node.js *

test/message/eval_messages.out

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ SyntaxError: Strict mode code may not include a with statement
1010
at [eval]-wrapper:*:*
1111
at evalScript (node:internal/process/execution:*:*)
1212
at node:internal/main/eval_string:*:*
13+
14+
Node.js *
1315
42
1416
42
1517
[eval]:1
@@ -25,6 +27,8 @@ Error: hello
2527
at evalScript (node:internal/process/execution:*:*)
2628
at node:internal/main/eval_string:*:*
2729

30+
Node.js *
31+
2832
[eval]:1
2933
throw new Error("hello")
3034
^
@@ -37,6 +41,8 @@ Error: hello
3741
at [eval]-wrapper:*:*
3842
at evalScript (node:internal/process/execution:*:*)
3943
at node:internal/main/eval_string:*:*
44+
45+
Node.js *
4046
100
4147
[eval]:1
4248
var x = 100; y = x;
@@ -51,15 +57,21 @@ ReferenceError: y is not defined
5157
at evalScript (node:internal/process/execution:*:*)
5258
at node:internal/main/eval_string:*:*
5359

60+
Node.js *
61+
5462
[eval]:1
5563
var ______________________________________________; throw 10
5664
^
5765
10
5866
(Use `* --trace-uncaught ...` to show where the exception was thrown)
5967

68+
Node.js *
69+
6070
[eval]:1
6171
var ______________________________________________; throw 10
6272
^
6373
10
6474
(Use `* --trace-uncaught ...` to show where the exception was thrown)
75+
76+
Node.js *
6577
done

test/message/events_unhandled_error_common_trace.out

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ Emitted 'error' event at:
1818
at Module._compile (node:internal/modules/cjs/loader:*:*)
1919
[... lines matching original stack trace ...]
2020
at node:internal/main/run_main_module:*:*
21+
22+
Node.js *

test/message/events_unhandled_error_nexttick.out

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Error
1313
Emitted 'error' event at:
1414
at *events_unhandled_error_nexttick.js:*:*
1515
at processTicksAndRejections (node:internal/process/task_queues:*:*)
16+
17+
Node.js *

test/message/events_unhandled_error_sameline.out

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ Emitted 'error' event at:
1515
at Module._compile (node:internal/modules/cjs/loader:*:*)
1616
[... lines matching original stack trace ...]
1717
at node:internal/main/run_main_module:*:*
18+
19+
Node.js *

test/message/events_unhandled_error_subclass.out

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ Emitted 'error' event on Foo instance at:
1515
at Module._compile (node:internal/modules/cjs/loader:*:*)
1616
[... lines matching original stack trace ...]
1717
at node:internal/main/run_main_module:*:*
18+
19+
Node.js *

test/message/if-error-has-good-stack.out

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
3333
expected: null,
3434
operator: 'ifError'
3535
}
36+
37+
Node.js *

test/message/internal_assert.out

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ Please open an issue with this stack trace at https://github.com/nodejs/node/iss
1616
at * {
1717
code: 'ERR_INTERNAL_ASSERTION'
1818
}
19+
20+
Node.js *

test/message/internal_assert_fail.out

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ Please open an issue with this stack trace at https://github.com/nodejs/node/iss
1717
at * {
1818
code: 'ERR_INTERNAL_ASSERTION'
1919
}
20+
21+
Node.js *

test/message/nexttick_throw.out

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
ReferenceError: undefined_reference_error_maker is not defined
66
at *test*message*nexttick_throw.js:*:*
77
at processTicksAndRejections (node:internal/process/task_queues:*:*)
8+
9+
Node.js *

test/message/promise_always_throw_unhandled.out

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ Error: One
1111
at *
1212
at *
1313
at *
14+
15+
Node.js *

test/message/source_map_disabled_by_api.out

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ Error: an error!
2424
at Module.load (node:internal/modules/cjs/loader:*)
2525
at Function.Module._load (node:internal/modules/cjs/loader:*)
2626
at Module.require (node:internal/modules/cjs/loader:*)
27+
28+
Node.js *

test/message/source_map_enabled_by_api.out

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ Error: an error!
2828
at Module.load (node:internal/modules/cjs/loader:*)
2929
at Function.Module._load (node:internal/modules/cjs/loader:*)
3030
at Module.require (node:internal/modules/cjs/loader:*)
31+
32+
Node.js *

test/message/source_map_enclosing_function.out

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Error: an error!
1313
at Module.load (node:internal/modules/cjs/loader:*)
1414
at Function.Module._load (node:internal/modules/cjs/loader:*)
1515
at Module.require (node:internal/modules/cjs/loader:*)
16+
17+
Node.js *

test/message/source_map_reference_error_tabs.out

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ ReferenceError: alert is not defined
1313
at require (node:internal/modules/cjs/helpers:*
1414
at Object.<anonymous> (*source_map_reference_error_tabs.js:*
1515
at Module._compile (node:internal/modules/cjs/loader:*
16+
17+
Node.js *

test/message/source_map_throw_first_tick.out

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Error: an exception
1313
at require (node:internal/modules/cjs/helpers:*)
1414
at Object.<anonymous> (*source_map_throw_first_tick.js:5:1)
1515
at Module._compile (node:internal/modules/cjs/loader:*)
16+
17+
Node.js *

test/message/source_map_throw_icu.out

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Error: an error
1313
at require (node:internal/modules/cjs/helpers:*
1414
at Object.<anonymous> (*source_map_throw_icu.js:*
1515
at Module._compile (node:internal/modules/cjs/loader:*
16+
17+
Node.js *

test/message/source_map_throw_set_immediate.out

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ Error: goodbye
66
at Hello *uglify-throw-original.js:5:9*
77
at *uglify-throw-original.js:9:3*
88
at processImmediate (node:internal/timers:*)
9+
10+
Node.js *

test/message/stack_overflow.out

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ JSON.stringify(array);
44
^
55

66
[RangeError: Maximum call stack size exceeded]
7+
8+
Node.js *

test/message/stdin_messages.out

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ SyntaxError: Strict mode code may not include a with statement
1414
at Socket.<anonymous> (node:internal/process/execution:*:*)
1515
at Socket.emit (node:events:*:*)
1616
at endReadableNT (node:internal/streams/readable:*:*)
17+
18+
Node.js *
1719
42
1820
42
1921
[stdin]:1
@@ -31,6 +33,8 @@ Error: hello
3133
at Socket.<anonymous> (node:internal/process/execution:*:*)
3234
at Socket.emit (node:events:*:*)
3335
at endReadableNT (node:internal/streams/readable:*:*)
36+
37+
Node.js *
3438
[stdin]:1
3539
throw new Error("hello")
3640
^
@@ -46,6 +50,8 @@ Error: hello
4650
at Socket.<anonymous> (node:internal/process/execution:*:*)
4751
at Socket.emit (node:events:*:*)
4852
at endReadableNT (node:internal/streams/readable:*:*)
53+
54+
Node.js *
4955
100
5056
[stdin]:1
5157
let x = 100; y = x;
@@ -63,15 +69,21 @@ ReferenceError: y is not defined
6369
at Socket.emit (node:events:*:*)
6470
at endReadableNT (node:internal/streams/readable:*:*)
6571

72+
Node.js *
73+
6674
[stdin]:1
6775
let ______________________________________________; throw 10
6876
^
6977
10
7078
(Use `* --trace-uncaught ...` to show where the exception was thrown)
7179

80+
Node.js *
81+
7282
[stdin]:1
7383
let ______________________________________________; throw 10
7484
^
7585
10
7686
(Use `* --trace-uncaught ...` to show where the exception was thrown)
87+
88+
Node.js *
7789
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Flags: --no-extra-info-on-fatal-exception
2+
3+
'use strict';
4+
require('../common');
5+
6+
throw new Error('foo');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*:6
2+
throw new Error('foo');
3+
^
4+
5+
Error: foo
6+
at Object.<anonymous> (*:6:7)
7+
at Module._compile (node:internal/modules/cjs/loader:*:*)
8+
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
9+
at Module.load (node:internal/modules/cjs/loader:*:*)
10+
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
11+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
12+
at node:internal/main/run_main_module:*:*

test/message/throw_custom_error.out

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
throw ({ name: 'MyCustomError', message: 'This is a custom message' });
33
^
44
{ name: 'MyCustomError', message: 'This is a custom message' }
5+
6+
Node.js *

test/message/throw_error_with_getter_throw.out

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ throw { // eslint-disable-line no-throw-literal
44
^
55
[object Object]
66
(Use `* --trace-uncaught ...` to show where the exception was thrown)
7+
8+
Node.js *

test/message/throw_error_with_getter_throw_traced.out

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ Thrown at:
1111
at Module._load (node:internal/modules/cjs/loader:*:*)
1212
at executeUserEntryPoint (node:internal/modules/run_main:*:*)
1313
at node:internal/main/run_main_module:*:*
14+
15+
Node.js *

test/message/throw_in_line_with_tabs.out

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ before
33
throw ({ foo: 'bar' });
44
^
55
{ foo: 'bar' }
6+
7+
Node.js *

test/message/throw_non_error.out

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
throw ({ foo: 'bar' });
33
^
44
{ foo: 'bar' }
5+
6+
Node.js *

test/message/throw_null.out

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ throw null;
44
^
55
null
66
(Use `* --trace-uncaught ...` to show where the exception was thrown)
7+
8+
Node.js *

test/message/throw_null_traced.out

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ Thrown at:
1111
at Module._load (node:internal/modules/cjs/loader:*:*)
1212
at executeUserEntryPoint (node:internal/modules/run_main:*:*)
1313
at node:internal/main/run_main_module:*:*
14+
15+
Node.js *

0 commit comments

Comments
 (0)