summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyles Borins <mylesborins@google.com>2020-02-17 20:36:50 -0500
committerMyles Borins <mylesborins@google.com>2020-02-17 20:57:44 -0500
commita5bc00af12c73ca5086578a995a2157503d67f0e (patch)
tree53467ccced13a12d36db552754e04fba8a557c5b
parent51fdd759b928ad6dbc41963d1a3a47b042e594b4 (diff)
downloadnode-new-a5bc00af12c73ca5086578a995a2157503d67f0e.tar.gz
Revert "events: allow monitoring error events"
This reverts commit 5cb0de948dde157f007a1bbbd9337859112a5b0f.
-rw-r--r--doc/api/events.md25
-rw-r--r--lib/events.js14
-rw-r--r--test/parallel/test-event-emitter-error-monitor.js32
3 files changed, 2 insertions, 69 deletions
diff --git a/doc/api/events.md b/doc/api/events.md
index dfa8189dbd..93939131a5 100644
--- a/doc/api/events.md
+++ b/doc/api/events.md
@@ -155,18 +155,6 @@ myEmitter.emit('error', new Error('whoops!'));
// Prints: whoops! there was an error
```
-It is possible to monitor `'error'` events without consuming the emitted error
-by installing a listener using the symbol `errorMonitor`.
-
-```js
-const myEmitter = new MyEmitter();
-myEmitter.on(EventEmitter.errorMonitor, (err) => {
- MyMonitoringTool.log(err);
-});
-myEmitter.emit('error', new Error('whoops!'));
-// Still throws and crashes Node.js
-```
-
## Capture Rejections of Promises
> Stability: 1 - captureRejections is experimental.
@@ -360,19 +348,6 @@ the event emitter instance, the event’s name and the number of attached
listeners, respectively.
Its `name` property is set to `'MaxListenersExceededWarning'`.
-### `EventEmitter.errorMonitor`
-<!-- YAML
-added: v12.16.0
--->
-
-This symbol shall be used to install a listener for only monitoring `'error'`
-events. Listeners installed using this symbol are called before the regular
-`'error'` listeners are called.
-
-Installing a listener using this symbol does not change the behavior once an
-`'error'` event is emitted, therefore the process will still crash if no
-regular `'error'` listener is installed.
-
### `emitter.addListener(eventName, listener)`
<!-- YAML
added: v0.1.26
diff --git a/lib/events.js b/lib/events.js
index 76b376e789..62ed219172 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -60,7 +60,6 @@ const {
} = require('internal/util/inspect');
const kCapture = Symbol('kCapture');
-const kErrorMonitor = Symbol('events.errorMonitor');
function EventEmitter(opts) {
EventEmitter.init.call(this, opts);
@@ -90,13 +89,6 @@ ObjectDefineProperty(EventEmitter, 'captureRejections', {
enumerable: true
});
-ObjectDefineProperty(EventEmitter, 'errorMonitor', {
- value: kErrorMonitor,
- writable: false,
- configurable: true,
- enumerable: true
-});
-
// The default for captureRejections is false
ObjectDefineProperty(EventEmitter.prototype, kCapture, {
value: false,
@@ -270,11 +262,9 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
let doError = (type === 'error');
const events = this._events;
- if (events !== undefined) {
- if (doError && events[kErrorMonitor] !== undefined)
- this.emit(kErrorMonitor, ...args);
+ if (events !== undefined)
doError = (doError && events.error === undefined);
- } else if (!doError)
+ else if (!doError)
return false;
// If there is no 'error' event listener then throw.
diff --git a/test/parallel/test-event-emitter-error-monitor.js b/test/parallel/test-event-emitter-error-monitor.js
deleted file mode 100644
index ba02839a84..0000000000
--- a/test/parallel/test-event-emitter-error-monitor.js
+++ /dev/null
@@ -1,32 +0,0 @@
-'use strict';
-const common = require('../common');
-const assert = require('assert');
-const EventEmitter = require('events');
-
-const EE = new EventEmitter();
-const theErr = new Error('MyError');
-
-EE.on(
- EventEmitter.errorMonitor,
- common.mustCall(function onErrorMonitor(e) {
- assert.strictEqual(e, theErr);
- }, 3)
-);
-
-// Verify with no error listener
-common.expectsError(
- () => EE.emit('error', theErr), theErr
-);
-
-// Verify with error listener
-EE.once('error', common.mustCall((e) => assert.strictEqual(e, theErr)));
-EE.emit('error', theErr);
-
-
-// Verify it works with once
-process.nextTick(() => EE.emit('error', theErr));
-assert.rejects(EventEmitter.once(EE, 'notTriggered'), theErr);
-
-// Only error events trigger error monitor
-EE.on('aEvent', common.mustCall());
-EE.emit('aEvent');