Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: improve multiple callback error message #12520

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ function afterTransform(stream, er, data) {

var cb = ts.writecb;

if (!cb)
return stream.emit('error', new Error('no writecb in Transform class'));
if (!cb) {
return stream.emit('error',
new Error('write callback called multiple times'));
}

ts.writechunk = null;
ts.writecb = null;
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-stream-transform-callback-twice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { Transform } = require('stream');
const stream = new Transform({
transform(chunk, enc, cb) { cb(); cb(); }
});

stream.on('error', common.mustCall((err) => {
assert.strictEqual(err.toString(),
'Error: write callback called multiple times');
}));

stream.write('foo');