Skip to content

Commit f36c970

Browse files
cjihrigjasnell
authored andcommitted
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>
1 parent 511ee24 commit f36c970

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/_stream_transform.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ function afterTransform(stream, er, data) {
8888

8989
var cb = ts.writecb;
9090

91-
if (!cb)
92-
return stream.emit('error', new Error('no writecb in Transform class'));
91+
if (!cb) {
92+
return stream.emit('error',
93+
new Error('write callback called multiple times'));
94+
}
9395

9496
ts.writechunk = null;
9597
ts.writecb = null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { Transform } = require('stream');
5+
const stream = new Transform({
6+
transform(chunk, enc, cb) { cb(); cb(); }
7+
});
8+
9+
stream.on('error', common.mustCall((err) => {
10+
assert.strictEqual(err.toString(),
11+
'Error: write callback called multiple times');
12+
}));
13+
14+
stream.write('foo');

0 commit comments

Comments
 (0)