Skip to content

Commit

Permalink
stream: throw invalid arg type from End Of Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJithil committed Jan 30, 2022
1 parent 44f8b4f commit 936291d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const {
codes,
} = require('internal/errors');
const {
ERR_STREAM_PREMATURE_CLOSE
ERR_STREAM_PREMATURE_CLOSE,
ERR_INVALID_ARG_TYPE
} = codes;
const { once } = require('internal/util');
const {
Expand Down Expand Up @@ -55,8 +56,7 @@ function eos(stream, options, callback) {
const writable = options.writable ?? isWritableNodeStream(stream);

if (!isNodeStream(stream)) {
// TODO: Webstreams.
// TODO: Throw INVALID_ARG_TYPE.
throw new ERR_INVALID_ARG_TYPE('stream', 'Stream', stream);
}

const wState = stream._writableState;
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-stream-end-of-streams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
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',
name: 'TypeError',
message: /stream/,
}
);

const streamObj = new Duplex();
streamObj.end();
// Below code should not throw any errors as the
// streamObj is `Stream`
finished(streamObj, () => {});

0 comments on commit 936291d

Please sign in to comment.