File tree 2 files changed +29
-5
lines changed
2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -1542,11 +1542,6 @@ function reduceToSingleString(
1542
1542
return `${ braces [ 0 ] } ${ ln } ${ join ( output , `,\n${ indentation } ` ) } ${ braces [ 1 ] } ` ;
1543
1543
}
1544
1544
1545
- function format ( ...args ) {
1546
- return formatWithOptions ( undefined , ...args ) ;
1547
- }
1548
-
1549
-
1550
1545
const firstErrorLine = ( error ) => error . message . split ( '\n' ) [ 0 ] ;
1551
1546
let CIRCULAR_ERROR_MESSAGE ;
1552
1547
function tryStringify ( arg ) {
@@ -1569,7 +1564,19 @@ function tryStringify(arg) {
1569
1564
}
1570
1565
}
1571
1566
1567
+ function format ( ...args ) {
1568
+ return formatWithOptionsInternal ( undefined , ...args ) ;
1569
+ }
1570
+
1572
1571
function 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 ) {
1573
1580
const first = args [ 0 ] ;
1574
1581
let a = 0 ;
1575
1582
let str = '' ;
Original file line number Diff line number Diff line change @@ -408,3 +408,20 @@ assert.strictEqual(
408
408
) ,
409
409
'[ 1, [Object] ]'
410
410
) ;
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