From dc58731e28a7c4a81d4e7c1ad88a16684930c5c7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 18 Oct 2019 17:05:35 +0200 Subject: [PATCH] cli: add --trace-uncaught flag Add a flag that makes Node.js print the stack trace at the time of *throwing* uncaught exceptions, rather than at the creation of the `Error` object, if there is any. This is disabled by default because it affects GC behavior. PR-URL: https://github.com/nodejs/node/pull/30025 Reviewed-By: James M Snell Reviewed-By: Richard Lau Reviewed-By: Ruben Bridgewater Reviewed-By: Gireesh Punathil --- doc/api/cli.md | 13 +++++++++++++ doc/node.1 | 12 ++++++++++++ src/node.cc | 2 ++ src/node_errors.cc | 13 +++++++++++++ src/node_options.cc | 4 ++++ src/node_options.h | 1 + test/message/eval_messages.out | 2 ++ test/message/stdin_messages.out | 2 ++ test/message/throw_error_with_getter_throw.out | 1 + .../message/throw_error_with_getter_throw_traced.js | 11 +++++++++++ .../throw_error_with_getter_throw_traced.out | 12 ++++++++++++ test/message/throw_null.out | 1 + test/message/throw_null_traced.js | 6 ++++++ test/message/throw_null_traced.out | 12 ++++++++++++ test/message/throw_undefined.out | 1 + test/message/throw_undefined_traced.js | 6 ++++++ test/message/throw_undefined_traced.out | 12 ++++++++++++ 17 files changed, 111 insertions(+) create mode 100644 test/message/throw_error_with_getter_throw_traced.js create mode 100644 test/message/throw_error_with_getter_throw_traced.out create mode 100644 test/message/throw_null_traced.js create mode 100644 test/message/throw_null_traced.out create mode 100644 test/message/throw_undefined_traced.js create mode 100644 test/message/throw_undefined_traced.out diff --git a/doc/api/cli.md b/doc/api/cli.md index 4cb33a157a7230..0b232b5a797d45 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -785,6 +785,18 @@ added: v12.2.0 Prints TLS packet trace information to `stderr`. This can be used to debug TLS connection problems. +### `--trace-uncaught` + + +Print stack traces for uncaught exceptions; usually, the stack trace associated +with the creation of an `Error` is printed, whereas this makes Node.js also +print the stack trace associated with throwing the value (which does not need +to be an `Error` instance). + +Enabling this option may affect garbage collection behavior negatively. + ### `--trace-warnings`