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 <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>
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

Lines changed: 8 additions & 0 deletions

doc/node.1

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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.

0 commit comments

Comments
 (0)