Skip to content

Commit e902fad

Browse files
ronagTrott
authored andcommitted
stream: do not throw multiple callback errors in writable
Align ERR_MULTIPLE_CALLBACK in Writable with the rest of error handling as well as how the error is implemented in Transform. PR-URL: #30614 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent decc5f5 commit e902fad

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/_stream_writable.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,10 @@ function onwrite(stream, er) {
477477
const sync = state.sync;
478478
const cb = state.writecb;
479479

480-
if (typeof cb !== 'function')
481-
throw new ERR_MULTIPLE_CALLBACK();
480+
if (typeof cb !== 'function') {
481+
errorOrDestroy(stream, new ERR_MULTIPLE_CALLBACK());
482+
return;
483+
}
482484

483485
state.writing = false;
484486
state.writecb = null;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { Writable } = require('stream');
4+
const stream = new Writable({
5+
write(chunk, enc, cb) { cb(); cb(); }
6+
});
7+
8+
stream.on('error', common.expectsError({
9+
type: Error,
10+
message: 'Callback called multiple times',
11+
code: 'ERR_MULTIPLE_CALLBACK'
12+
}));
13+
14+
stream.write('foo');

0 commit comments

Comments
 (0)