mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
stream: convert premature close to AbortError
AbortError is a more "web" align alternative to ERR_STREAM_PREMATURE_CLOSE. PR-URL: https://github.com/nodejs/node/pull/39524 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
b14fb01324
commit
3f0b62375b
4 files changed
+19
-6
No files matched your search
@@ -50,6 +50,7 @@ const {
|
||||
ERR_INVALID_STATE,
|
||||
ERR_STREAM_PREMATURE_CLOSE,
|
||||
},
|
||||
AbortError,
|
||||
} = require('internal/errors');
|
||||
|
||||
const {
|
||||
@@ -120,6 +121,12 @@ function newWritableStreamFromStreamWritable(streamWritable) {
|
||||
}
|
||||
|
||||
const cleanup = finished(streamWritable, (error) => {
|
||||
if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
|
||||
const err = new AbortError();
|
||||
err.cause = error;
|
||||
error = err;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
// This is a protection against non-standard, legacy streams
|
||||
// that happen to emit an error event again after finished is called.
|
||||
@@ -144,7 +151,7 @@ function newWritableStreamFromStreamWritable(streamWritable) {
|
||||
closed = undefined;
|
||||
return;
|
||||
}
|
||||
controller.error(new ERR_STREAM_PREMATURE_CLOSE());
|
||||
controller.error(new AbortError());
|
||||
controller = undefined;
|
||||
});
|
||||
|
||||
@@ -395,6 +402,12 @@ function newReadableStreamFromStreamReadable(streamReadable) {
|
||||
streamReadable.pause();
|
||||
|
||||
const cleanup = finished(streamReadable, (error) => {
|
||||
if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
|
||||
const err = new AbortError();
|
||||
err.cause = error;
|
||||
error = err;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
// This is a protection against non-standard, legacy streams
|
||||
// that happen to emit an error event again after finished is called.
|
||||
|
||||
@@ -59,7 +59,7 @@ const {
|
||||
const reader = readableStream.getReader();
|
||||
|
||||
assert.rejects(reader.closed, {
|
||||
code: 'ERR_STREAM_PREMATURE_CLOSE',
|
||||
code: 'ABORT_ERR',
|
||||
});
|
||||
|
||||
readable.on('end', common.mustNotCall());
|
||||
|
||||
@@ -27,11 +27,11 @@ const {
|
||||
const writer = writable.getWriter();
|
||||
|
||||
assert.rejects(reader.closed, {
|
||||
code: 'ERR_STREAM_PREMATURE_CLOSE',
|
||||
code: 'ABORT_ERR',
|
||||
});
|
||||
|
||||
assert.rejects(writer.closed, {
|
||||
code: 'ERR_STREAM_PREMATURE_CLOSE',
|
||||
code: 'ABORT_ERR',
|
||||
});
|
||||
|
||||
duplex.destroy();
|
||||
@@ -165,7 +165,7 @@ const {
|
||||
|
||||
reader.closed.then(common.mustCall());
|
||||
assert.rejects(writer.closed, {
|
||||
code: 'ERR_STREAM_PREMATURE_CLOSE',
|
||||
code: 'ABORT_ERR',
|
||||
});
|
||||
|
||||
duplex.end();
|
||||
|
||||
@@ -92,7 +92,7 @@ class TestWritable extends Writable {
|
||||
const writableStream = newWritableStreamFromStreamWritable(writable);
|
||||
|
||||
assert.rejects(writableStream.close(), {
|
||||
code: 'ERR_STREAM_PREMATURE_CLOSE'
|
||||
code: 'ABORT_ERR'
|
||||
});
|
||||
|
||||
writable.end();
|
||||
|
||||
Reference in new issue
Block a user