-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
events: show throw stack trace for uncaught exception
Show the stack trace for the `eventemitter.emit('error')` call in the case of an uncaught exception. Previously, there would be no clue in Node’s output about where the actual `throw` comes from. PR-URL: #19003 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
10 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
require('../common'); | ||
const EventEmitter = require('events'); | ||
|
||
function foo() { | ||
function bar() { | ||
return new Error('foo:bar'); | ||
} | ||
|
||
return bar(); | ||
} | ||
|
||
const ee = new EventEmitter(); | ||
const err = foo(); | ||
|
||
function quux() { | ||
ee.emit('error', err); | ||
} | ||
|
||
quux(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
events.js:* | ||
throw er; // Unhandled 'error' event | ||
^ | ||
|
||
Error: foo:bar | ||
at bar (*events_unhandled_error_common_trace.js:*:*) | ||
at foo (*events_unhandled_error_common_trace.js:*:*) | ||
at Object.<anonymous> (*events_unhandled_error_common_trace.js:*:*) | ||
at Module._compile (module.js:*:*) | ||
at Object.Module._extensions..js (module.js:*:*) | ||
at Module.load (module.js:*:*) | ||
at tryModuleLoad (module.js:*:*) | ||
at Function.Module._load (module.js:*:*) | ||
at Function.Module.runMain (module.js:*:*) | ||
at startup (bootstrap_node.js:*:*) | ||
Emitted 'error' event at: | ||
at quux (*events_unhandled_error_common_trace.js:*:*) | ||
at Object.<anonymous> (*events_unhandled_error_common_trace.js:*:*) | ||
at Module._compile (module.js:*:*) | ||
[... lines matching original stack trace ...] | ||
at startup (bootstrap_node.js:*:*) | ||
at bootstrap_node.js:*:* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
require('../common'); | ||
const EventEmitter = require('events'); | ||
const er = new Error(); | ||
process.nextTick(() => { | ||
new EventEmitter().emit('error', er); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
events.js:* | ||
throw er; // Unhandled 'error' event | ||
^ | ||
|
||
Error | ||
at Object.<anonymous> (*events_unhandled_error_nexttick.js:*:*) | ||
at Module._compile (module.js:*:*) | ||
at Object.Module._extensions..js (module.js:*:*) | ||
at Module.load (module.js:*:*) | ||
at tryModuleLoad (module.js:*:*) | ||
at Function.Module._load (module.js:*:*) | ||
at Function.Module.runMain (module.js:*:*) | ||
at startup (bootstrap_node.js:*:*) | ||
at bootstrap_node.js:*:* | ||
Emitted 'error' event at: | ||
at process.nextTick (*events_unhandled_error_nexttick.js:*:*) | ||
at process._tickCallback (internal/process/next_tick.js:*:*) | ||
at Function.Module.runMain (module.js:*:*) | ||
at startup (bootstrap_node.js:*:*) | ||
at bootstrap_node.js:*:* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
require('../common'); | ||
const EventEmitter = require('events'); | ||
new EventEmitter().emit('error', new Error()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
events.js:* | ||
throw er; // Unhandled 'error' event | ||
^ | ||
|
||
Error | ||
at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*) | ||
at Module._compile (module.js:*:*) | ||
at Object.Module._extensions..js (module.js:*:*) | ||
at Module.load (module.js:*:*) | ||
at tryModuleLoad (module.js:*:*) | ||
at Function.Module._load (module.js:*:*) | ||
at Function.Module.runMain (module.js:*:*) | ||
at startup (bootstrap_node.js:*:*) | ||
at bootstrap_node.js:*:* | ||
Emitted 'error' event at: | ||
at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*) | ||
at Module._compile (module.js:*:*) | ||
[... lines matching original stack trace ...] | ||
at bootstrap_node.js:*:* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const EventEmitter = require('events'); | ||
|
||
// Tests that the error stack where the exception was thrown is *not* appended. | ||
|
||
process.on('uncaughtException', common.mustCall((err) => { | ||
const lines = err.stack.split('\n'); | ||
assert.strictEqual(lines[0], 'Error'); | ||
lines.slice(1).forEach((line) => { | ||
assert(/^ at/.test(line), `${line} has an unexpected format`); | ||
}); | ||
})); | ||
|
||
new EventEmitter().emit('error', new Error()); |