Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: throw invalid arg type from End Of Stream #41766

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
codes,
} = require('internal/errors');
const {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PREMATURE_CLOSE
} = codes;
const { once } = require('internal/util');
Expand Down Expand Up @@ -56,7 +57,7 @@ function eos(stream, options, callback) {

if (!isNodeStream(stream)) {
// TODO: Webstreams.
MrJithil marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Throw INVALID_ARG_TYPE.
throw new ERR_INVALID_ARG_TYPE('stream', 'Stream', stream);
}

const wState = stream._writableState;
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-stream-end-of-streams.js
Original file line number Diff line number Diff line change
@@ -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, () => {});
7 changes: 6 additions & 1 deletion test/parallel/test-stream-finished.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down