summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-02-26 15:46:50 +0100
committerAnna Henningsen <anna@addaleax.net>2018-03-04 21:20:43 +0000
commit68d508a9e03923a5ae6a53a1adff66c4e3f97263 (patch)
tree5994954cfd307defe8bd7805aea06f17ebf9b444 /test
parentf2d93795bfe61a3260bf743d2247b56b83fc6f70 (diff)
downloadandroid-node-v8-68d508a9e03923a5ae6a53a1adff66c4e3f97263.tar.gz
android-node-v8-68d508a9e03923a5ae6a53a1adff66c4e3f97263.tar.bz2
android-node-v8-68d508a9e03923a5ae6a53a1adff66c4e3f97263.zip
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: https://github.com/nodejs/node/pull/19003 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/message/events_unhandled_error_common_trace.js20
-rw-r--r--test/message/events_unhandled_error_common_trace.out22
-rw-r--r--test/message/events_unhandled_error_nexttick.js7
-rw-r--r--test/message/events_unhandled_error_nexttick.out20
-rw-r--r--test/message/events_unhandled_error_sameline.js4
-rw-r--r--test/message/events_unhandled_error_sameline.out19
-rw-r--r--test/parallel/test-events-uncaught-exception-stack.js16
7 files changed, 108 insertions, 0 deletions
diff --git a/test/message/events_unhandled_error_common_trace.js b/test/message/events_unhandled_error_common_trace.js
new file mode 100644
index 0000000000..e6c168fc06
--- /dev/null
+++ b/test/message/events_unhandled_error_common_trace.js
@@ -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();
diff --git a/test/message/events_unhandled_error_common_trace.out b/test/message/events_unhandled_error_common_trace.out
new file mode 100644
index 0000000000..d39a95cb77
--- /dev/null
+++ b/test/message/events_unhandled_error_common_trace.out
@@ -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:*:*
diff --git a/test/message/events_unhandled_error_nexttick.js b/test/message/events_unhandled_error_nexttick.js
new file mode 100644
index 0000000000..713031eeef
--- /dev/null
+++ b/test/message/events_unhandled_error_nexttick.js
@@ -0,0 +1,7 @@
+'use strict';
+require('../common');
+const EventEmitter = require('events');
+const er = new Error();
+process.nextTick(() => {
+ new EventEmitter().emit('error', er);
+});
diff --git a/test/message/events_unhandled_error_nexttick.out b/test/message/events_unhandled_error_nexttick.out
new file mode 100644
index 0000000000..f0591610ff
--- /dev/null
+++ b/test/message/events_unhandled_error_nexttick.out
@@ -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:*:*
diff --git a/test/message/events_unhandled_error_sameline.js b/test/message/events_unhandled_error_sameline.js
new file mode 100644
index 0000000000..1e5e77d08c
--- /dev/null
+++ b/test/message/events_unhandled_error_sameline.js
@@ -0,0 +1,4 @@
+'use strict';
+require('../common');
+const EventEmitter = require('events');
+new EventEmitter().emit('error', new Error());
diff --git a/test/message/events_unhandled_error_sameline.out b/test/message/events_unhandled_error_sameline.out
new file mode 100644
index 0000000000..100c294276
--- /dev/null
+++ b/test/message/events_unhandled_error_sameline.out
@@ -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:*:*
diff --git a/test/parallel/test-events-uncaught-exception-stack.js b/test/parallel/test-events-uncaught-exception-stack.js
new file mode 100644
index 0000000000..c55322a5aa
--- /dev/null
+++ b/test/parallel/test-events-uncaught-exception-stack.js
@@ -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());