Skip to content

Commit 63391e7

Browse files
hazelpinca
andauthored
stream: add new when constructing ERR_MULTIPLE_CALLBACK
commit c71e548 changed NodeError from a function to a class, and missed a spot where `ERR_MULTIPLE_CALLBACK` was being instantiated. This commit fixes that by adding the new keyword to that instance. Co-authored-by: Luigi Pinca <luigipinca@gmail.com> PR-URL: #52110 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 454d080 commit 63391e7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/internal/streams/writable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ function needFinish(state) {
876876

877877
function onFinish(stream, state, err) {
878878
if ((state[kState] & kPrefinished) !== 0) {
879-
errorOrDestroy(stream, err ?? ERR_MULTIPLE_CALLBACK());
879+
errorOrDestroy(stream, err ?? new ERR_MULTIPLE_CALLBACK());
880880
return;
881881
}
882882
state.pendingcb--;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
const common = require('../common');
3+
const stream = require('stream');
4+
const assert = require('assert');
5+
6+
class TestWritable extends stream.Writable {
7+
_write(_chunk, _encoding, callback) {
8+
callback();
9+
}
10+
11+
_final(callback) {
12+
process.nextTick(callback);
13+
process.nextTick(callback);
14+
}
15+
}
16+
17+
const writable = new TestWritable();
18+
19+
writable.on('finish', common.mustCall());
20+
writable.on('error', common.mustCall((error) => {
21+
assert.strictEqual(error.message, 'Callback called multiple times');
22+
}));
23+
24+
writable.write('some data');
25+
writable.end();

0 commit comments

Comments
 (0)