Skip to content
Permalink
Browse files

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 <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
ronag authored and Trott committed Nov 23, 2019
1 parent decc5f5 commit e902fadc5ee7615b15ce86d1986785c169d59c01
Showing with 18 additions and 2 deletions.
  1. +4 −2 lib/_stream_writable.js
  2. +14 −0 test/parallel/test-stream-writable-callback-twice.js
@@ -477,8 +477,10 @@ function onwrite(stream, er) {
const sync = state.sync;
const cb = state.writecb;

if (typeof cb !== 'function')
throw new ERR_MULTIPLE_CALLBACK();
if (typeof cb !== 'function') {
errorOrDestroy(stream, new ERR_MULTIPLE_CALLBACK());
return;
}

state.writing = false;
state.writecb = null;
@@ -0,0 +1,14 @@
'use strict';
const common = require('../common');
const { Writable } = require('stream');
const stream = new Writable({
write(chunk, enc, cb) { cb(); cb(); }
});

stream.on('error', common.expectsError({
type: Error,
message: 'Callback called multiple times',
code: 'ERR_MULTIPLE_CALLBACK'
}));

stream.write('foo');

0 comments on commit e902fad

Please sign in to comment.
You can’t perform that action at this time.