| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2621,6 +2621,12 @@ or a pipeline ends non gracefully with no explicit error. | |||
| 2621 | 2621 | An attempt was made to call [`stream.push()`][] after a `null`(EOF) had been | |
| 2622 | 2622 | pushed to the stream. | |
| 2623 | 2623 | ||
| 2624 | + <a id="ERR_STREAM_UNABLE_TO_PIPE"></a> | ||
| 2625 | + | ||
| 2626 | + ### `ERR_STREAM_UNABLE_TO_PIPE` | ||
| 2627 | + | ||
| 2628 | + An attempt was made to pipe to a closed or destroyed stream in a pipeline. | ||
| 2629 | + | ||
| 2624 | 2630 | <a id="ERR_STREAM_UNSHIFT_AFTER_END_EVENT"></a> | |
| 2625 | 2631 | ||
| 2626 | 2632 | ### `ERR_STREAM_UNSHIFT_AFTER_END_EVENT` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1716,6 +1716,7 @@ E('ERR_STREAM_DESTROYED', 'Cannot call %s after a stream was destroyed', Error); | |||
| 1716 | 1716 | E('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError); | |
| 1717 | 1717 | E('ERR_STREAM_PREMATURE_CLOSE', 'Premature close', Error); | |
| 1718 | 1718 | E('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF', Error); | |
| 1719 | + E('ERR_STREAM_UNABLE_TO_PIPE', 'Connot pipe to a closed or destroyed stream', Error); | ||
| 1719 | 1720 | E('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', | |
| 1720 | 1721 | 'stream.unshift() after end event', Error); | |
| 1721 | 1722 | E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode', Error); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ const { | |||
| 23 | 23 | ERR_MISSING_ARGS, | |
| 24 | 24 | ERR_STREAM_DESTROYED, | |
| 25 | 25 | ERR_STREAM_PREMATURE_CLOSE, | |
| 26 | + ERR_STREAM_UNABLE_TO_PIPE, | ||
| 26 | 27 | }, | |
| 27 | 28 | } = require('internal/errors'); | |
| 28 | 29 | ||
@@ -253,10 +254,15 @@ function pipelineImpl(streams, callback, opts) { | |||
| 253 | 254 | const stream = streams[i]; | |
| 254 | 255 | const reading = i < streams.length - 1; | |
| 255 | 256 | const writing = i > 0; | |
| 257 | + const next = i + 1 < streams.length ? streams[i + 1] : null; | ||
| 256 | 258 | const end = reading || opts?.end !== false; | |
| 257 | 259 | const isLastStream = i === streams.length - 1; | |
| 258 | 260 | ||
| 259 | 261 | if (isNodeStream(stream)) { | |
| 262 | + if (next !== null && (next?.closed || next?.destroyed)) { | ||
| 263 | + throw new ERR_STREAM_UNABLE_TO_PIPE(); | ||
| 264 | + } | ||
| 265 | + | ||
| 260 | 266 | if (end) { | |
| 261 | 267 | const { destroy, cleanup } = destroyer(stream, reading, writing); | |
| 262 | 268 | destroys.push(destroy); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,8 @@ const http = require('http'); | |||
| 17 | 17 | const { promisify } = require('util'); | |
| 18 | 18 | const net = require('net'); | |
| 19 | 19 | const tsp = require('timers/promises'); | |
| 20 | + const tmpdir = require('../common/tmpdir'); | ||
| 21 | + const fs = require('fs'); | ||
| 20 | 22 | ||
| 21 | 23 | { | |
| 22 | 24 | let finished = false; | |
@@ -69,6 +71,17 @@ const tsp = require('timers/promises'); | |||
| 69 | 71 | }, /ERR_INVALID_ARG_TYPE/); | |
| 70 | 72 | } | |
| 71 | 73 | ||
| 74 | + tmpdir.refresh(); | ||
| 75 | + { | ||
| 76 | + assert.rejects(async () => { | ||
| 77 | + const read = fs.createReadStream(__filename); | ||
| 78 | + const write = fs.createWriteStream(tmpdir.resolve('a')); | ||
| 79 | + const close = promisify(write.close); | ||
| 80 | + await close.call(write); | ||
| 81 | + await pipelinep(read, write); | ||
| 82 | + }, /ERR_STREAM_UNABLE_TO_PIPE/).then(common.mustCall()); | ||
| 83 | + } | ||
| 84 | + | ||
| 72 | 85 | { | |
| 73 | 86 | const read = new Readable({ | |
| 74 | 87 | read() {} | |
| Back | FazBrowse Home | New Git URL |
0 commit comments