Permalink
Browse files

stream: improve multiple callback error message

When a transform stream's callback is called more than once,
an error is emitted with a somewhat confusing message. This
commit hopes to improve the quality of the error message.

Fixes: #12513
PR-URL: #12520
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
cjihrig authored and jasnell committed Apr 19, 2017
1 parent 511ee24 commit f36c970cf3517f8585b884b2c58ff2d8b853c9e6
Showing with 18 additions and 2 deletions.
  1. +4 −2 lib/_stream_transform.js
  2. +14 −0 test/parallel/test-stream-transform-callback-twice.js
View
@@ -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;
@@ -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');

0 comments on commit f36c970

Please sign in to comment.