| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 85898e0 commit db706da
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1703,6 +1703,12 @@ An attempt was made to call [`stream.pipe()`][] on a [`Writable`][] stream. | |||
| 1703 | 1703 | A stream method was called that cannot complete because the stream was | |
| 1704 | 1704 | destroyed using `stream.destroy()`. | |
| 1705 | 1705 | ||
| 1706 | + <a id="ERR_STREAM_ALREADY_FINISHED"></a> | ||
| 1707 | + ### ERR_STREAM_ALREADY_FINISHED | ||
| 1708 | + | ||
| 1709 | + A stream method was called that cannot complete because the stream was | ||
| 1710 | + finished. | ||
| 1711 | + | ||
| 1706 | 1712 | <a id="ERR_STREAM_NULL_VALUES"></a> | |
| 1707 | 1713 | ### ERR_STREAM_NULL_VALUES | |
| 1708 | 1714 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ const { | |||
| 46 | 46 | ERR_INVALID_CHAR, | |
| 47 | 47 | ERR_METHOD_NOT_IMPLEMENTED, | |
| 48 | 48 | ERR_STREAM_CANNOT_PIPE, | |
| 49 | + ERR_STREAM_ALREADY_FINISHED, | ||
| 49 | 50 | ERR_STREAM_WRITE_AFTER_END | |
| 50 | 51 | }, | |
| 51 | 52 | hideStackFrames | |
@@ -704,6 +705,13 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { | |||
| 704 | 705 | } | |
| 705 | 706 | ||
| 706 | 707 | if (this.finished) { | |
| 708 | + if (typeof callback === 'function') { | ||
| 709 | + if (!this.writableFinished) { | ||
| 710 | + this.on('finish', callback); | ||
| 711 | + } else { | ||
| 712 | + callback(new ERR_STREAM_ALREADY_FINISHED('end')); | ||
| 713 | + } | ||
| 714 | + } | ||
| 707 | 715 | return this; | |
| 708 | 716 | } | |
| 709 | 717 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ const { | |||
| 41 | 41 | ERR_MULTIPLE_CALLBACK, | |
| 42 | 42 | ERR_STREAM_CANNOT_PIPE, | |
| 43 | 43 | ERR_STREAM_DESTROYED, | |
| 44 | + ERR_STREAM_ALREADY_FINISHED, | ||
| 44 | 45 | ERR_STREAM_NULL_VALUES, | |
| 45 | 46 | ERR_STREAM_WRITE_AFTER_END, | |
| 46 | 47 | ERR_UNKNOWN_ENCODING | |
@@ -591,6 +592,13 @@ Writable.prototype.end = function(chunk, encoding, cb) { | |||
| 591 | 592 | // Ignore unnecessary end() calls. | |
| 592 | 593 | if (!state.ending) | |
| 593 | 594 | endWritable(this, state, cb); | |
| 595 | + else if (typeof cb === 'function') { | ||
| 596 | + if (!state.finished) { | ||
| 597 | + this.once('finish', cb); | ||
| 598 | + } else { | ||
| 599 | + cb(new ERR_STREAM_ALREADY_FINISHED('end')); | ||
| 600 | + } | ||
| 601 | + } | ||
| 594 | 602 | ||
| 595 | 603 | return this; | |
| 596 | 604 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1128,6 +1128,9 @@ E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running', Error); | |||
| 1128 | 1128 | E('ERR_SRI_PARSE', | |
| 1129 | 1129 | 'Subresource Integrity string %s had an unexpected at %d', | |
| 1130 | 1130 | SyntaxError); | |
| 1131 | + E('ERR_STREAM_ALREADY_FINISHED', | ||
| 1132 | + 'Cannot call %s after a stream was finished', | ||
| 1133 | + Error); | ||
| 1131 | 1134 | E('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable', Error); | |
| 1132 | 1135 | E('ERR_STREAM_DESTROYED', 'Cannot call %s after a stream was destroyed', Error); | |
| 1133 | 1136 | E('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const http = require('http'); | ||
| 5 | + | ||
| 6 | + const server = http.createServer(common.mustCall(function(req, res) { | ||
| 7 | + res.end('testing ended state', common.mustCall()); | ||
| 8 | + res.end(common.mustCall()); | ||
| 9 | + res.on('finish', common.mustCall(() => { | ||
| 10 | + res.end(common.mustCall((err) => { | ||
| 11 | + assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED'); | ||
| 12 | + server.close(); | ||
| 13 | + })); | ||
| 14 | + })); | ||
| 15 | + })); | ||
| 16 | + | ||
| 17 | + server.listen(0); | ||
| 18 | + | ||
| 19 | + server.on('listening', common.mustCall(function() { | ||
| 20 | + http | ||
| 21 | + .request({ | ||
| 22 | + port: server.address().port, | ||
| 23 | + method: 'GET', | ||
| 24 | + path: '/' | ||
| 25 | + }) | ||
| 26 | + .end(); | ||
| 27 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,20 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const stream = require('stream'); | ||
| 7 | + | ||
| 8 | + const writable = new stream.Writable(); | ||
| 9 | + | ||
| 10 | + writable._write = (chunk, encoding, cb) => { | ||
| 11 | + setTimeout(() => cb(), 10); | ||
| 12 | + }; | ||
| 13 | + | ||
| 14 | + writable.end('testing ended state', common.mustCall()); | ||
| 15 | + writable.end(common.mustCall()); | ||
| 16 | + writable.on('finish', common.mustCall(() => { | ||
| 17 | + writable.end(common.mustCall((err) => { | ||
| 18 | + assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED'); | ||
| 19 | + })); | ||
| 20 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments