File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -1542,11 +1542,6 @@ function reduceToSingleString(
15421542 return `${ braces [ 0 ] } ${ ln } ${ join ( output , `,\n${ indentation } ` ) } ${ braces [ 1 ] } ` ;
15431543}
15441544
1545- function format ( ...args ) {
1546- return formatWithOptions ( undefined , ...args ) ;
1547- }
1548-
1549-
15501545const firstErrorLine = ( error ) => error . message . split ( '\n' ) [ 0 ] ;
15511546let CIRCULAR_ERROR_MESSAGE ;
15521547function tryStringify ( arg ) {
@@ -1569,7 +1564,19 @@ function tryStringify(arg) {
15691564 }
15701565}
15711566
1567+ function format ( ...args ) {
1568+ return formatWithOptionsInternal ( undefined , ...args ) ;
1569+ }
1570+
15721571function formatWithOptions ( inspectOptions , ...args ) {
1572+ if ( typeof inspectOptions !== 'object' || inspectOptions === null ) {
1573+ throw new ERR_INVALID_ARG_TYPE (
1574+ 'inspectOptions' , 'object' , inspectOptions ) ;
1575+ }
1576+ return formatWithOptionsInternal ( inspectOptions , ...args ) ;
1577+ }
1578+
1579+ function formatWithOptionsInternal ( inspectOptions , ...args ) {
15731580 const first = args [ 0 ] ;
15741581 let a = 0 ;
15751582 let str = '' ;
Original file line number Diff line number Diff line change @@ -408,3 +408,20 @@ assert.strictEqual(
408408 ) ,
409409 '[ 1, [Object] ]'
410410) ;
411+
412+ [
413+ undefined ,
414+ null ,
415+ false ,
416+ 5n ,
417+ 5 ,
418+ 'test' ,
419+ Symbol ( )
420+ ] . forEach ( ( invalidOptions ) => {
421+ assert . throws ( ( ) => {
422+ util . formatWithOptions ( invalidOptions , { a : true } ) ;
423+ } , {
424+ code : 'ERR_INVALID_ARG_TYPE' ,
425+ message : / " i n s p e c t O p t i o n s " .+ o b j e c t /
426+ } ) ;
427+ } ) ;
You can’t perform that action at this time.
0 commit comments