Skip to content

Commit f0a5218

Browse files
committed
lib: throw invalid arg type from End Of Stream
1 parent 44f8b4f commit f0a5218

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const {
88
codes,
99
} = require('internal/errors');
1010
const {
11-
ERR_STREAM_PREMATURE_CLOSE
11+
ERR_STREAM_PREMATURE_CLOSE,
12+
ERR_INVALID_ARG_TYPE
1213
} = codes;
1314
const { once } = require('internal/util');
1415
const {
@@ -55,8 +56,7 @@ function eos(stream, options, callback) {
5556
const writable = options.writable ?? isWritableNodeStream(stream);
5657

5758
if (!isNodeStream(stream)) {
58-
// TODO: Webstreams.
59-
// TODO: Throw INVALID_ARG_TYPE.
59+
throw new ERR_INVALID_ARG_TYPE('stream', 'stream.Stream', stream);
6060
}
6161

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

0 commit comments

Comments
 (0)