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:
Jithil P Ponnan 2022-02-11 03:04:59 +05:30 committed by GitHub
parent bde184e8ab
commit fe7ca085a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -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;

View 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, () => {});

View File

@ -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');
}