Skip to content

Commit 23f6626

Browse files
committed
stream: throw invalid arg type from End Of Stream
1 parent 6edd9a5 commit 23f6626

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/internal/streams/end-of-stream.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
codes,
99
} = require('internal/errors');
1010
const {
11+
ERR_INVALID_ARG_TYPE,
1112
ERR_STREAM_PREMATURE_CLOSE
1213
} = codes;
1314
const { once } = require('internal/util');
@@ -56,7 +57,7 @@ function eos(stream, options, callback) {
5657

5758
if (!isNodeStream(stream)) {
5859
// TODO: Webstreams.
59-
// TODO: Throw INVALID_ARG_TYPE.
60+
throw new ERR_INVALID_ARG_TYPE('stream', 'Stream', stream);
6061
}
6162

6263
const wState = stream._writableState;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
5+
const { Duplex, finished } = require('stream');
6+
7+
assert.throws(
8+
() => {
9+
// Passing empty object to mock invalid stream
10+
// should throw error
11+
finished({}, () => {});
12+
},
13+
{
14+
code: 'ERR_INVALID_ARG_TYPE',
15+
name: 'TypeError',
16+
message: /stream/,
17+
}
18+
);
19+
20+
const streamObj = new Duplex();
21+
streamObj.end();
22+
// Below code should not throw any errors as the
23+
// streamObj is `Stream`
24+
finished(streamObj, () => {});

0 commit comments

Comments
 (0)