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.

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>
  • Loading branch information
2 people authored and marco-ippolito committed May 3, 2024
1 parent af7c55f commit f8209ff
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());
writable.on('error', common.mustCall((error) => {
assert.strictEqual(error.message, 'Callback called multiple times');
}));

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

0 comments on commit f8209ff

Please sign in to comment.