Skip to content

Commit

Permalink
net: throw error to given objectMode in connection
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde committed Oct 6, 2021
1 parent 87da53c commit 80e3dec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ function connect(...args) {
const normalized = normalizeArgs(args);
const options = normalized[0];
debug('createConnection', normalized);
if (options.objectMode) {
throw new ERR_INVALID_ARG_VALUE('options.objectMode', options.objectMode, 'is not supported');
}
const socket = new Socket(options);

if (options.timeout) {
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-net-connect-options-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const assert = require('assert');
const net = require('net');

{
const ArgValueInvalidError = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError'
};

const option = {objectMode: true};

assert.throws(() => {
net.createConnection(option);
}, {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: /The property 'options.objectMode' is not supported. Received true/
});
}

0 comments on commit 80e3dec

Please sign in to comment.