Skip to content

Commit

Permalink
stream: add new when constructing ERR_MULTIPLE_CALLBACK
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haze committed Mar 16, 2024
1 parent ba06c5c commit dcdcf76
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ function needFinish(state) {

function onFinish(stream, state, err) {
if ((state[kState] & kPrefinished) !== 0) {
errorOrDestroy(stream, err ?? ERR_MULTIPLE_CALLBACK());
errorOrDestroy(stream, err ?? new ERR_MULTIPLE_CALLBACK());
return;
}
state.pendingcb--;
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-stream-err-multiple-callback-construction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
const common = require('../common');
const stream = require('stream');
const assert = require('assert');

class TestWritable extends stream.Writable {
_write(_chunk, _encoding, callback) {
callback();
}

_final(callback) {
process.nextTick(callback);
process.nextTick(callback);
}
}

const writable = new TestWritable();

writable.on('finish', common.mustCall(1));
writable.on('error', common.mustCall((error) => {
assert.strictEqual(error.message, 'Callback called multiple times');
}));

writable.write('some data');
writable.end();

0 comments on commit dcdcf76

Please sign in to comment.