Skip to content

Commit 4a6a5c3

Browse files
committed
stream: improve comments regarding end() errors
Cleans up comments and TODOs and tries to provide a more detail description in regards to error behavior of end(). PR-URL: #32839 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 15cc2b6 commit 4a6a5c3

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

lib/_stream_writable.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -598,20 +598,16 @@ Writable.prototype.end = function(chunk, encoding, cb) {
598598
if (typeof cb !== 'function')
599599
cb = nop;
600600

601-
// Ignore unnecessary end() calls.
602-
// TODO(ronag): Compat. Allow end() after destroy().
601+
// This is forgiving in terms of unnecessary calls to end() and can hide
602+
// logic errors. However, usually such errors are harmless and causing a
603+
// hard error can be disproportionately destructive. It is not always
604+
// trivial for the user to determine whether end() needs to be called or not.
603605
if (!state.errored && !state.ending) {
604606
endWritable(this, state, cb);
605607
} else if (state.finished) {
606-
const err = new ERR_STREAM_ALREADY_FINISHED('end');
607-
process.nextTick(cb, err);
608-
// TODO(ronag): Compat. Don't error the stream.
609-
// errorOrDestroy(this, err, true);
608+
process.nextTick(cb, new ERR_STREAM_ALREADY_FINISHED('end'));
610609
} else if (state.destroyed) {
611-
const err = new ERR_STREAM_DESTROYED('end');
612-
process.nextTick(cb, err);
613-
// TODO(ronag): Compat. Don't error the stream.
614-
// errorOrDestroy(this, err, true);
610+
process.nextTick(cb, new ERR_STREAM_DESTROYED('end'));
615611
} else if (cb !== nop) {
616612
onFinished(this, state, cb);
617613
}
@@ -720,6 +716,7 @@ function onCorkedFinish(corkReq, state, err) {
720716
state.corkedRequestsFree.next = corkReq;
721717
}
722718

719+
// TODO(ronag): Avoid using events to implement internal logic.
723720
function onFinished(stream, state, cb) {
724721
function onerror(err) {
725722
stream.removeListener('finish', onfinish);

0 commit comments

Comments
 (0)