diff --git a/lib/net.js b/lib/net.js index ded48732c2e11e..95e36cda07c089 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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) { diff --git a/test/parallel/test-net-connect-options-invalid.js b/test/parallel/test-net-connect-options-invalid.js new file mode 100644 index 00000000000000..e30ab86a55bc3f --- /dev/null +++ b/test/parallel/test-net-connect-options-invalid.js @@ -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/ + }); +}