mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
stream: throw invalid arg type from End Of Stream
PR-URL: https://github.com/nodejs/node/pull/41766 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Mary Marchini <oss@mmarchini.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
bde184e8ab
commit
fe7ca085a7
@ -8,6 +8,7 @@ const {
|
||||
codes,
|
||||
} = require('internal/errors');
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_STREAM_PREMATURE_CLOSE
|
||||
} = codes;
|
||||
const { once } = require('internal/util');
|
||||
@ -58,7 +59,7 @@ function eos(stream, options, callback) {
|
||||
|
||||
if (!isNodeStream(stream)) {
|
||||
// TODO: Webstreams.
|
||||
// TODO: Throw INVALID_ARG_TYPE.
|
||||
throw new ERR_INVALID_ARG_TYPE('stream', 'Stream', stream);
|
||||
}
|
||||
|
||||
const wState = stream._writableState;
|
||||
|
20
test/parallel/test-stream-end-of-streams.js
Normal file
20
test/parallel/test-stream-end-of-streams.js
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const { Duplex, finished } = require('stream');
|
||||
|
||||
assert.throws(
|
||||
() => {
|
||||
// Passing empty object to mock invalid stream
|
||||
// should throw error
|
||||
finished({}, () => {});
|
||||
},
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
|
||||
const streamObj = new Duplex();
|
||||
streamObj.end();
|
||||
// Below code should not throw any errors as the
|
||||
// streamObj is `Stream`
|
||||
finished(streamObj, () => {});
|
@ -260,7 +260,12 @@ const http = require('http');
|
||||
const streamLike = new EE();
|
||||
streamLike.readableEnded = true;
|
||||
streamLike.readable = true;
|
||||
finished(streamLike, common.mustCall());
|
||||
assert.throws(
|
||||
() => {
|
||||
finished(streamLike, () => {});
|
||||
},
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
streamLike.emit('close');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user