Skip to content

Commit

Permalink
Revert "events: allow monitoring error events"
Browse files Browse the repository at this point in the history
This reverts commit 5cb0de9.
  • Loading branch information
MylesBorins committed Feb 18, 2020
1 parent 51fdd75 commit a5bc00a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 69 deletions.
25 changes: 0 additions & 25 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
32 changes: 0 additions & 32 deletions test/parallel/test-event-emitter-error-monitor.js

This file was deleted.

0 comments on commit a5bc00a

Please sign in to comment.