| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1aeca6d commit e08c008
17 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -775,6 +775,18 @@ added: v12.2.0 | |||
| 775 | 775 | Prints TLS packet trace information to `stderr`. This can be used to debug TLS | |
| 776 | 776 | connection problems. | |
| 777 | 777 | ||
| 778 | + ### `--trace-uncaught` | ||
| 779 | + <!-- YAML | ||
| 780 | + added: REPLACEME | ||
| 781 | + --> | ||
| 782 | + | ||
| 783 | + Print stack traces for uncaught exceptions; usually, the stack trace associated | ||
| 784 | + with the creation of an `Error` is printed, whereas this makes Node.js also | ||
| 785 | + print the stack trace associated with throwing the value (which does not need | ||
| 786 | + to be an `Error` instance). | ||
| 787 | + | ||
| 788 | + Enabling this option may affect garbage collection behavior negatively. | ||
| 789 | + | ||
| 778 | 790 | ### `--trace-warnings` | |
| 779 | 791 | <!-- YAML | |
| 780 | 792 | added: v6.0.0 | |
@@ -1089,6 +1101,7 @@ Node.js options that are allowed are: | |||
| 1089 | 1101 | * `--trace-events-enabled` | |
| 1090 | 1102 | * `--trace-sync-io` | |
| 1091 | 1103 | * `--trace-tls` | |
| 1104 | + * `--trace-uncaught` | ||
| 1092 | 1105 | * `--trace-warnings` | |
| 1093 | 1106 | * `--track-heap-objects` | |
| 1094 | 1107 | * `--unhandled-rejections` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,6 +346,18 @@ Print a stack trace whenever synchronous I/O is detected after the first turn of | |||
| 346 | 346 | .It Fl -trace-tls | |
| 347 | 347 | Prints TLS packet trace information to stderr. | |
| 348 | 348 | . | |
| 349 | + .It Fl -trace-uncaught | ||
| 350 | + Print stack traces for uncaught exceptions; usually, the stack trace associated | ||
| 351 | + with the creation of an | ||
| 352 | + .Sy Error | ||
| 353 | + is printed, whereas this makes Node.js also | ||
| 354 | + print the stack trace associated with throwing the value (which does not need | ||
| 355 | + to be an | ||
| 356 | + .Sy Error | ||
| 357 | + instance). | ||
| 358 | + .Pp | ||
| 359 | + Enabling this option may affect garbage collection behavior negatively. | ||
| 360 | + . | ||
| 349 | 361 | .It Fl -trace-warnings | |
| 350 | 362 | Print stack traces for process warnings (including deprecations). | |
| 351 | 363 | . | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -232,6 +232,8 @@ int Environment::InitializeInspector( | |||
| 232 | 232 | void Environment::InitializeDiagnostics() { | |
| 233 | 233 | isolate_->GetHeapProfiler()->AddBuildEmbedderGraphCallback( | |
| 234 | 234 | Environment::BuildEmbedderGraph, this); | |
| 235 | + if (options_->trace_uncaught) | ||
| 236 | + isolate_->SetCaptureStackTraceForUncaughtExceptions(true); | ||
| 235 | 237 | ||
| 236 | 238 | #if defined HAVE_DTRACE || defined HAVE_ETW | |
| 237 | 239 | InitDTrace(this); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -380,6 +380,19 @@ static void ReportFatalException(Environment* env, | |||
| 380 | 380 | "%s\n%s: %s\n", *arrow_string, *name_string, *message_string); | |
| 381 | 381 | } | |
| 382 | 382 | } | |
| 383 | + | ||
| 384 | + if (!env->options()->trace_uncaught) { | ||
| 385 | + PrintErrorString("(Use `node --trace-uncaught ...` to show " | ||
| 386 | + "where the exception was thrown)\n"); | ||
| 387 | + } | ||
| 388 | + } | ||
| 389 | + | ||
| 390 | + if (env->options()->trace_uncaught) { | ||
| 391 | + Local<StackTrace> trace = message->GetStackTrace(); | ||
| 392 | + if (!trace.IsEmpty()) { | ||
| 393 | + PrintErrorString("Thrown at:\n"); | ||
| 394 | + PrintStackTrace(env->isolate(), trace); | ||
| 395 | + } | ||
| 383 | 396 | } | |
| 384 | 397 | ||
| 385 | 398 | fflush(stderr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -494,6 +494,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 494 | 494 | "prints TLS packet trace information to stderr", | |
| 495 | 495 | &EnvironmentOptions::trace_tls, | |
| 496 | 496 | kAllowedInEnvironment); | |
| 497 | + AddOption("--trace-uncaught", | ||
| 498 | + "show stack traces for the `throw` behind uncaught exceptions", | ||
| 499 | + &EnvironmentOptions::trace_uncaught, | ||
| 500 | + kAllowedInEnvironment); | ||
| 497 | 501 | AddOption("--trace-warnings", | |
| 498 | 502 | "show stack traces on process warnings", | |
| 499 | 503 | &EnvironmentOptions::trace_warnings, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,6 +142,7 @@ class EnvironmentOptions : public Options { | |||
| 142 | 142 | bool trace_deprecation = false; | |
| 143 | 143 | bool trace_sync_io = false; | |
| 144 | 144 | bool trace_tls = false; | |
| 145 | + bool trace_uncaught = false; | ||
| 145 | 146 | bool trace_warnings = false; | |
| 146 | 147 | std::string unhandled_rejections; | |
| 147 | 148 | std::string userland_loader; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,9 +55,11 @@ ReferenceError: y is not defined | |||
| 55 | 55 | var ______________________________________________; throw 10 | |
| 56 | 56 | ^ | |
| 57 | 57 | 10 | |
| 58 | + (Use `node --trace-uncaught ...` to show where the exception was thrown) | ||
| 58 | 59 | ||
| 59 | 60 | [eval]:1 | |
| 60 | 61 | var ______________________________________________; throw 10 | |
| 61 | 62 | ^ | |
| 62 | 63 | 10 | |
| 64 | + (Use `node --trace-uncaught ...` to show where the exception was thrown) | ||
| 63 | 65 | done | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,9 +67,11 @@ ReferenceError: y is not defined | |||
| 67 | 67 | let ______________________________________________; throw 10 | |
| 68 | 68 | ^ | |
| 69 | 69 | 10 | |
| 70 | + (Use `node --trace-uncaught ...` to show where the exception was thrown) | ||
| 70 | 71 | ||
| 71 | 72 | [stdin]:1 | |
| 72 | 73 | let ______________________________________________; throw 10 | |
| 73 | 74 | ^ | |
| 74 | 75 | 10 | |
| 76 | + (Use `node --trace-uncaught ...` to show where the exception was thrown) | ||
| 75 | 77 | done | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,3 +3,4 @@ | |||
| 3 | 3 | throw { // eslint-disable-line no-throw-literal | |
| 4 | 4 | ^ | |
| 5 | 5 | [object Object] | |
| 6 | + (Use `node --trace-uncaught ...` to show where the exception was thrown) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + // Flags: --trace-uncaught | ||
| 2 | + 'use strict'; | ||
| 3 | + require('../common'); | ||
| 4 | + throw { // eslint-disable-line no-throw-literal | ||
| 5 | + get stack() { | ||
| 6 | + throw new Error('weird throw but ok'); | ||
| 7 | + }, | ||
| 8 | + get name() { | ||
| 9 | + throw new Error('weird throw but ok'); | ||
| 10 | + }, | ||
| 11 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments