GeezerVison is showing github.com — stream: ensure Stream.pipeline re-throws errors without callback · nodejs/node@c1012b4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/pipeline.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,10 @@ function once(callback) { | 19 | 19 | }; | 20 | 20 | } | 21 | 21 |
| 22 | | -function noop() {} | | 22 | +function noop(err) { | | 23 | + // Rethrow the error if it exists to avoid swallowing it | | 24 | + if (err) throw err; | | 25 | +} | 23 | 26 |
| 24 | 27 | function isRequest(stream) { | 25 | 28 | return stream.setHeader && typeof stream.abort === 'function'; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stream-pipeline.js +35-3Lines changed: 35 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -142,7 +142,7 @@ common.crashOnUnhandledRejection(); | 142 | 142 | } | 143 | 143 | }); | 144 | 144 |
| 145 | | - pipeline(rs, res); | | 145 | + pipeline(rs, res, () => {}); | 146 | 146 | }); | 147 | 147 |
| 148 | 148 | server.listen(0, () => { | @@ -177,7 +177,7 @@ common.crashOnUnhandledRejection(); | 177 | 177 | }) | 178 | 178 | }); | 179 | 179 |
| 180 | | - pipeline(rs, res); | | 180 | + pipeline(rs, res, () => {}); | 181 | 181 | }); | 182 | 182 |
| 183 | 183 | server.listen(0, () => { | @@ -206,7 +206,7 @@ common.crashOnUnhandledRejection(); | 206 | 206 | }) | 207 | 207 | }); | 208 | 208 |
| 209 | | - pipeline(rs, res); | | 209 | + pipeline(rs, res, () => {}); | 210 | 210 | }); | 211 | 211 |
| 212 | 212 | let cnt = 10; | @@ -481,3 +481,35 @@ common.crashOnUnhandledRejection(); | 481 | 481 |
| 482 | 482 | run(); | 483 | 483 | } | | 484 | + | | 485 | +{ | | 486 | + const read = new Readable({ | | 487 | + read() {} | | 488 | + }); | | 489 | + | | 490 | + const transform = new Transform({ | | 491 | + transform(data, enc, cb) { | | 492 | + cb(new Error('kaboom')); | | 493 | + } | | 494 | + }); | | 495 | + | | 496 | + const write = new Writable({ | | 497 | + write(data, enc, cb) { | | 498 | + cb(); | | 499 | + } | | 500 | + }); | | 501 | + | | 502 | + read.on('close', common.mustCall()); | | 503 | + transform.on('close', common.mustCall()); | | 504 | + write.on('close', common.mustCall()); | | 505 | + | | 506 | + process.on('uncaughtException', common.mustCall((err) => { | | 507 | + assert.deepStrictEqual(err, new Error('kaboom')); | | 508 | + })); | | 509 | + | | 510 | + const dst = pipeline(read, transform, write); | | 511 | + | | 512 | + assert.strictEqual(dst, write); | | 513 | + | | 514 | + read.push('hello'); | | 515 | +} |
|