| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 003ab59 commit ff34d48
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1021,6 +1021,9 @@ Default signal is `SIGUSR2`. | |||
| 1021 | 1021 | <!-- YAML | |
| 1022 | 1022 | added: v11.8.0 | |
| 1023 | 1023 | changes: | |
| 1024 | + - version: REPLACEME | ||
| 1025 | + pr-url: https://github.com/nodejs/node/pull/44208 | ||
| 1026 | + description: Report is not generated if the uncaught exception is handled. | ||
| 1024 | 1027 | - version: | |
| 1025 | 1028 | - v13.12.0 | |
| 1026 | 1029 | - v12.17.0 | |
@@ -1032,9 +1035,9 @@ changes: | |||
| 1032 | 1035 | `--report-uncaught-exception`. | |
| 1033 | 1036 | --> | |
| 1034 | 1037 | ||
| 1035 | - Enables report to be generated on uncaught exceptions. Useful when inspecting | ||
| 1036 | - the JavaScript stack in conjunction with native stack and other runtime | ||
| 1037 | - environment data. | ||
| 1038 | + Enables report to be generated when the process exits due to an uncaught | ||
| 1039 | + exception. Useful when inspecting the JavaScript stack in conjunction with | ||
| 1040 | + native stack and other runtime environment data. | ||
| 1038 | 1041 | ||
| 1039 | 1042 | ### `--secure-heap=n` | |
| 1040 | 1043 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,27 +139,6 @@ function createOnGlobalUncaughtException() { | |||
| 139 | 139 | // call that threw and was never cleared. So clear it now. | |
| 140 | 140 | clearDefaultTriggerAsyncId(); | |
| 141 | 141 | ||
| 142 | - // If diagnostic reporting is enabled, call into its handler to see | ||
| 143 | - // whether it is interested in handling the situation. | ||
| 144 | - // Ignore if the error is scoped inside a domain. | ||
| 145 | - // use == in the checks as we want to allow for null and undefined | ||
| 146 | - if (er == null || er.domain == null) { | ||
| 147 | - try { | ||
| 148 | - const report = internalBinding('report'); | ||
| 149 | - if (report != null && report.shouldReportOnUncaughtException()) { | ||
| 150 | - report.writeReport( | ||
| 151 | - typeof er?.message === 'string' ? | ||
| 152 | - er.message : | ||
| 153 | - 'Exception', | ||
| 154 | - 'Exception', | ||
| 155 | - null, | ||
| 156 | - er ?? {}); | ||
| 157 | - } | ||
| 158 | - } catch { | ||
| 159 | - // Ignore the exception. Diagnostic reporting is unavailable. | ||
| 160 | - } | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | 142 | const type = fromPromise ? 'unhandledRejection' : 'uncaughtException'; | |
| 164 | 143 | process.emit('uncaughtExceptionMonitor', er, type); | |
| 165 | 144 | if (exceptionHandlerState.captureFn !== null) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -354,6 +354,7 @@ static void ReportFatalException(Environment* env, | |||
| 354 | 354 | } | |
| 355 | 355 | ||
| 356 | 356 | node::Utf8Value trace(env->isolate(), stack_trace); | |
| 357 | + std::string report_message = "Exception"; | ||
| 357 | 358 | ||
| 358 | 359 | // range errors have a trace member set to undefined | |
| 359 | 360 | if (trace.length() > 0 && !stack_trace->IsUndefined()) { | |
@@ -386,6 +387,8 @@ static void ReportFatalException(Environment* env, | |||
| 386 | 387 | } else { | |
| 387 | 388 | node::Utf8Value name_string(env->isolate(), name.ToLocalChecked()); | |
| 388 | 389 | node::Utf8Value message_string(env->isolate(), message.ToLocalChecked()); | |
| 390 | + // Update the report message if it is an object has message property. | ||
| 391 | + report_message = message_string.ToString(); | ||
| 389 | 392 | ||
| 390 | 393 | if (arrow.IsEmpty() || !arrow->IsString() || decorated) { | |
| 391 | 394 | FPrintF(stderr, "%s: %s\n", name_string, message_string); | |
@@ -407,6 +410,11 @@ static void ReportFatalException(Environment* env, | |||
| 407 | 410 | } | |
| 408 | 411 | } | |
| 409 | 412 | ||
| 413 | + if (env->isolate_data()->options()->report_uncaught_exception) { | ||
| 414 | + report::TriggerNodeReport( | ||
| 415 | + isolate, env, report_message.c_str(), "Exception", "", error); | ||
| 416 | + } | ||
| 417 | + | ||
| 410 | 418 | if (env->options()->trace_uncaught) { | |
| 411 | 419 | Local<StackTrace> trace = message->GetStackTrace(); | |
| 412 | 420 | if (!trace.IsEmpty()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,32 @@ | |||
| 1 | - // Flags: --experimental-report --report-uncaught-exception --report-compact | ||
| 2 | 1 | 'use strict'; | |
| 3 | - // Test producing a compact report on uncaught exception. | ||
| 4 | - require('../common'); | ||
| 5 | - require('./test-report-uncaught-exception.js'); | ||
| 2 | + // Test producing a report on uncaught exception. | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const childProcess = require('child_process'); | ||
| 6 | + const helper = require('../common/report'); | ||
| 7 | + const tmpdir = require('../common/tmpdir'); | ||
| 8 | + | ||
| 9 | + if (process.argv[2] === 'child') { | ||
| 10 | + throw new Error('test error'); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + tmpdir.refresh(); | ||
| 14 | + const child = childProcess.spawn(process.execPath, [ | ||
| 15 | + '--report-uncaught-exception', | ||
| 16 | + '--report-compact', | ||
| 17 | + __filename, | ||
| 18 | + 'child', | ||
| 19 | + ], { | ||
| 20 | + cwd: tmpdir.path | ||
| 21 | + }); | ||
| 22 | + child.on('exit', common.mustCall((code) => { | ||
| 23 | + assert.strictEqual(code, 1); | ||
| 24 | + const reports = helper.findReports(child.pid, tmpdir.path); | ||
| 25 | + assert.strictEqual(reports.length, 1); | ||
| 26 | + | ||
| 27 | + helper.validate(reports[0], [ | ||
| 28 | + ['header.event', 'Exception'], | ||
| 29 | + ['header.trigger', 'Exception'], | ||
| 30 | + ['javascriptStack.message', 'Error: test error'], | ||
| 31 | + ]); | ||
| 32 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + // Flags: --report-uncaught-exception | ||
| 2 | + 'use strict'; | ||
| 3 | + // Test report is suppressed on uncaught exception hook. | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const helper = require('../common/report'); | ||
| 7 | + const tmpdir = require('../common/tmpdir'); | ||
| 8 | + const error = new Error('test error'); | ||
| 9 | + | ||
| 10 | + tmpdir.refresh(); | ||
| 11 | + process.report.directory = tmpdir.path; | ||
| 12 | + | ||
| 13 | + // Make sure the uncaughtException listener is called. | ||
| 14 | + process.on('uncaughtException', common.mustCall()); | ||
| 15 | + | ||
| 16 | + process.on('exit', (code) => { | ||
| 17 | + assert.strictEqual(code, 0); | ||
| 18 | + // Make sure no reports are generated. | ||
| 19 | + const reports = helper.findReports(process.pid, tmpdir.path); | ||
| 20 | + assert.strictEqual(reports.length, 0); | ||
| 21 | + }); | ||
| 22 | + | ||
| 23 | + throw error; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,9 +12,7 @@ process.report.directory = tmpdir.path; | |||
| 12 | 12 | ||
| 13 | 13 | // First, install an uncaught exception hook. | |
| 14 | 14 | process.setUncaughtExceptionCaptureCallback(common.mustCall()); | |
| 15 | - | ||
| 16 | - // Make sure this is ignored due to the above override. | ||
| 17 | - process.on('uncaughtException', common.mustNotCall()); | ||
| 15 | + // Do not install process uncaughtException handler. | ||
| 18 | 16 | ||
| 19 | 17 | process.on('exit', (code) => { | |
| 20 | 18 | assert.strictEqual(code, 0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,25 +1,32 @@ | |||
| 1 | - // Flags: --report-uncaught-exception | ||
| 2 | 1 | 'use strict'; | |
| 3 | 2 | // Test producing a report on uncaught exception. | |
| 4 | 3 | const common = require('../common'); | |
| 5 | 4 | const assert = require('assert'); | |
| 5 | + const childProcess = require('child_process'); | ||
| 6 | 6 | const helper = require('../common/report'); | |
| 7 | 7 | const tmpdir = require('../common/tmpdir'); | |
| 8 | 8 | ||
| 9 | - const exception = 1; | ||
| 9 | + if (process.argv[2] === 'child') { | ||
| 10 | + // eslint-disable-next-line no-throw-literal | ||
| 11 | + throw 1; | ||
| 12 | + } | ||
| 10 | 13 | ||
| 11 | 14 | tmpdir.refresh(); | |
| 12 | - process.report.directory = tmpdir.path; | ||
| 13 | - | ||
| 14 | - process.on('uncaughtException', common.mustCall((err) => { | ||
| 15 | - assert.strictEqual(err, exception); | ||
| 16 | - const reports = helper.findReports(process.pid, tmpdir.path); | ||
| 15 | + const child = childProcess.spawn(process.execPath, [ | ||
| 16 | + '--report-uncaught-exception', | ||
| 17 | + __filename, | ||
| 18 | + 'child', | ||
| 19 | + ], { | ||
| 20 | + cwd: tmpdir.path, | ||
| 21 | + }); | ||
| 22 | + child.on('exit', common.mustCall((code) => { | ||
| 23 | + assert.strictEqual(code, 1); | ||
| 24 | + const reports = helper.findReports(child.pid, tmpdir.path); | ||
| 17 | 25 | assert.strictEqual(reports.length, 1); | |
| 18 | 26 | ||
| 19 | 27 | helper.validate(reports[0], [ | |
| 20 | 28 | ['header.event', 'Exception'], | |
| 21 | - ['javascriptStack.message', `${exception}`], | ||
| 29 | + ['header.trigger', 'Exception'], | ||
| 30 | + ['javascriptStack.message', '1'], | ||
| 22 | 31 | ]); | |
| 23 | 32 | })); | |
| 24 | - | ||
| 25 | - throw exception; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,25 +1,31 @@ | |||
| 1 | - // Flags: --report-uncaught-exception | ||
| 2 | 1 | 'use strict'; | |
| 3 | 2 | // Test producing a report on uncaught exception. | |
| 4 | 3 | const common = require('../common'); | |
| 5 | 4 | const assert = require('assert'); | |
| 5 | + const childProcess = require('child_process'); | ||
| 6 | 6 | const helper = require('../common/report'); | |
| 7 | 7 | const tmpdir = require('../common/tmpdir'); | |
| 8 | 8 | ||
| 9 | - const exception = Symbol('foobar'); | ||
| 9 | + if (process.argv[2] === 'child') { | ||
| 10 | + throw Symbol('foobar'); | ||
| 11 | + } | ||
| 10 | 12 | ||
| 11 | 13 | tmpdir.refresh(); | |
| 12 | - process.report.directory = tmpdir.path; | ||
| 13 | - | ||
| 14 | - process.on('uncaughtException', common.mustCall((err) => { | ||
| 15 | - assert.strictEqual(err, exception); | ||
| 16 | - const reports = helper.findReports(process.pid, tmpdir.path); | ||
| 14 | + const child = childProcess.spawn(process.execPath, [ | ||
| 15 | + '--report-uncaught-exception', | ||
| 16 | + __filename, | ||
| 17 | + 'child', | ||
| 18 | + ], { | ||
| 19 | + cwd: tmpdir.path, | ||
| 20 | + }); | ||
| 21 | + child.on('exit', common.mustCall((code) => { | ||
| 22 | + assert.strictEqual(code, 1); | ||
| 23 | + const reports = helper.findReports(child.pid, tmpdir.path); | ||
| 17 | 24 | assert.strictEqual(reports.length, 1); | |
| 18 | 25 | ||
| 19 | 26 | helper.validate(reports[0], [ | |
| 20 | 27 | ['header.event', 'Exception'], | |
| 28 | + ['header.trigger', 'Exception'], | ||
| 21 | 29 | ['javascriptStack.message', 'Symbol(foobar)'], | |
| 22 | 30 | ]); | |
| 23 | 31 | })); | |
| 24 | - | ||
| 25 | - throw exception; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,20 +1,31 @@ | |||
| 1 | - // Flags: --report-uncaught-exception | ||
| 2 | 1 | 'use strict'; | |
| 3 | 2 | // Test producing a report on uncaught exception. | |
| 4 | 3 | const common = require('../common'); | |
| 5 | 4 | const assert = require('assert'); | |
| 5 | + const childProcess = require('child_process'); | ||
| 6 | 6 | const helper = require('../common/report'); | |
| 7 | 7 | const tmpdir = require('../common/tmpdir'); | |
| 8 | - const error = new Error('test error'); | ||
| 9 | 8 | ||
| 10 | - tmpdir.refresh(); | ||
| 11 | - process.report.directory = tmpdir.path; | ||
| 9 | + if (process.argv[2] === 'child') { | ||
| 10 | + throw new Error('test error'); | ||
| 11 | + } | ||
| 12 | 12 | ||
| 13 | - process.on('uncaughtException', common.mustCall((err) => { | ||
| 14 | - assert.strictEqual(err, error); | ||
| 15 | - const reports = helper.findReports(process.pid, tmpdir.path); | ||
| 13 | + tmpdir.refresh(); | ||
| 14 | + const child = childProcess.spawn(process.execPath, [ | ||
| 15 | + '--report-uncaught-exception', | ||
| 16 | + __filename, | ||
| 17 | + 'child', | ||
| 18 | + ], { | ||
| 19 | + cwd: tmpdir.path, | ||
| 20 | + }); | ||
| 21 | + child.on('exit', common.mustCall((code) => { | ||
| 22 | + assert.strictEqual(code, 1); | ||
| 23 | + const reports = helper.findReports(child.pid, tmpdir.path); | ||
| 16 | 24 | assert.strictEqual(reports.length, 1); | |
| 17 | - helper.validate(reports[0]); | ||
| 18 | - })); | ||
| 19 | 25 | ||
| 20 | - throw error; | ||
| 26 | + helper.validate(reports[0], [ | ||
| 27 | + ['header.event', 'Exception'], | ||
| 28 | + ['header.trigger', 'Exception'], | ||
| 29 | + ['javascriptStack.message', 'Error: test error'], | ||
| 30 | + ]); | ||
| 31 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments