From ce0bc3031c9b83667cf4fc1b6a9fb62dbc4f26fd Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 18 Oct 2019 17:05:35 +0200 Subject: [PATCH 1/2] 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. --- doc/api/cli.md | 13 +++++++++++++ doc/node.1 | 12 ++++++++++++ src/env.cc | 3 +++ 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, 112 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 ed2a0f1b1ce9a5..cbff194e87c99e 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -747,6 +747,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`