Skip to content

Commit

Permalink
stream: writable don't throw multiple callback error
Browse files Browse the repository at this point in the history
Align ERR_MULTIPLE_CALLBACK in Writable with the rest
of error handling as well as how the error is implemented
in Transform.
  • Loading branch information
ronag committed Nov 23, 2019
1 parent f171112 commit b1320d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,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;
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-stream-writable-callback-twice copy.js
Original file line number Diff line number Diff line change
@@ -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 b1320d8

Please sign in to comment.