-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: catch and forward error from dest.write
- Loading branch information
1 parent
7ae193d
commit de9f68a
Showing
2 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
test/parallel/test-stream-pipe-objectmode-to-non-objectmode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use strict'; | ||
|
||
/** | ||
* source is an object mode stream that only flows strings/buffer and the error is unrelated | ||
* source is a binary stream and dest is a binary stream | ||
*/ | ||
const common = require('../common'); | ||
const assert = require('node:assert'); | ||
const { Readable, Transform, Writable } = require('node:stream'); | ||
|
||
{ | ||
const objectReadable = Readable.from([ | ||
{ hello: 'hello' }, | ||
{ world: 'world' }, | ||
]); | ||
|
||
const passThrough = new Transform({ | ||
transform(chunk, _encoding, cb) { | ||
this.push(chunk); | ||
cb(null); | ||
}, | ||
}); | ||
|
||
passThrough.on('error', common.mustCall()); | ||
|
||
objectReadable.pipe(passThrough); | ||
|
||
assert.rejects(async () => { | ||
// eslint-disable-next-line no-unused-vars | ||
for await (const _ of passThrough); | ||
}, /ERR_INVALID_ARG_TYPE/).then(common.mustCall()); | ||
} | ||
|
||
{ | ||
const stringReadable = Readable.from(['hello', 'world']); | ||
|
||
const passThrough = new Transform({ | ||
transform(chunk, _encoding, cb) { | ||
this.push(chunk); | ||
throw new Error('something went wrong'); | ||
}, | ||
}); | ||
|
||
passThrough.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'something went wrong'); | ||
})); | ||
|
||
stringReadable.pipe(passThrough); | ||
} | ||
|
||
{ | ||
const binaryData = Buffer.from('binary data'); | ||
|
||
const binaryReadable = new Readable({ | ||
read() { | ||
this.push(binaryData); | ||
this.push(null); | ||
} | ||
}); | ||
|
||
const binaryWritable = new Writable({ | ||
write(chunk, _encoding, cb) { | ||
throw new Error('something went wrong'); | ||
} | ||
}); | ||
|
||
binaryWritable.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'something went wrong'); | ||
})); | ||
binaryReadable.pipe(binaryWritable); | ||
} |