File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed
Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ const WriteWrap = process.binding('stream_wrap').WriteWrap;
4242const async_id_symbol = process . binding ( 'async_wrap' ) . async_id_symbol ;
4343const { newUid, setInitTriggerId } = require ( 'async_hooks' ) ;
4444const nextTick = require ( 'internal/process/next_tick' ) . nextTick ;
45+ const errors = require ( 'internal/errors' ) ;
4546
4647var cluster ;
4748var dns ;
@@ -964,8 +965,9 @@ Socket.prototype.connect = function() {
964965 this . _sockname = null ;
965966 }
966967
967- var pipe = ! ! options . path ;
968- debug ( 'pipe' , pipe , options . path ) ;
968+ const path = options . path ;
969+ var pipe = ! ! path ;
970+ debug ( 'pipe' , pipe , path ) ;
969971
970972 if ( ! this . _handle ) {
971973 this . _handle = pipe ? new Pipe ( ) : new TCP ( ) ;
@@ -982,7 +984,13 @@ Socket.prototype.connect = function() {
982984 this . writable = true ;
983985
984986 if ( pipe ) {
985- internalConnect ( this , options . path ) ;
987+ if ( typeof path !== 'string' ) {
988+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' ,
989+ 'options.path' ,
990+ 'string' ,
991+ path ) ;
992+ }
993+ internalConnect ( this , path ) ;
986994 } else {
987995 lookupAndConnect ( this , options ) ;
988996 }
Original file line number Diff line number Diff line change 22const common = require ( '../common' ) ;
33const net = require ( 'net' ) ;
44const assert = require ( 'assert' ) ;
5- const fp = '/tmp/fadagagsdfgsdf' ;
6- const c = net . connect ( fp ) ;
75
8- c . on ( 'connect' , common . mustNotCall ( ) ) ;
6+ {
7+ const fp = '/tmp/fadagagsdfgsdf' ;
8+ const c = net . connect ( fp ) ;
99
10- c . on ( 'error' , common . mustCall ( function ( e ) {
11- assert . strictEqual ( e . code , 'ENOENT' ) ;
12- assert . strictEqual ( e . message , `connect ENOENT ${ fp } ` ) ;
13- } ) ) ;
10+ c . on ( 'connect' , common . mustNotCall ( ) ) ;
11+ c . on ( 'error' , common . expectsError ( {
12+ code : 'ENOENT' ,
13+ message : `connect ENOENT ${ fp } `
14+ } ) ) ;
15+ }
16+
17+ {
18+ assert . throws (
19+ ( ) => net . createConnection ( { path : { } } ) ,
20+ common . expectsError ( { code : 'ERR_INVALID_ARG_TYPE' } )
21+ ) ;
22+ }
You can’t perform that action at this time.
0 commit comments