@@ -1480,6 +1480,90 @@ E('ERR_INVALID_CHAR',
1480
1480
if ( field !== undefined ) {
1481
1481
msg += ` ["${ field } "]` ;
1482
1482
}
1483
+ return msg ;
1484
+ } , TypeError , HideStackFramesError ) ;
1485
+ E ( 'ERR_INVALID_CONTAINER_ELEMENT_TYPE' ,
1486
+ ( containerName , key , expected , actual ) => {
1487
+ assert ( typeof containerName === 'string' , "'containerName' must be a string" ) ;
1488
+ assert ( typeof key === 'string' || typeof key === 'number' || typeof key === 'symbol' ,
1489
+ "'key' must be a string, number, or symbol" ) ;
1490
+ if ( ! ArrayIsArray ( expected ) ) {
1491
+ expected = [ expected ] ;
1492
+ }
1493
+
1494
+ let elementRef ;
1495
+ if ( typeof key === 'number' ) {
1496
+ elementRef = `"${ containerName } [${ key } ]"` ;
1497
+ } else if ( typeof key === 'string' ) {
1498
+ elementRef = `"${ containerName } " element "${ key } "` ;
1499
+ } else {
1500
+ // Handle symbol keys
1501
+ const symbolDesc = key . description ;
1502
+ const symbolStr = String ( key ) ;
1503
+ if ( symbolDesc !== undefined ) {
1504
+ elementRef = `"${ containerName } " element "${ symbolDesc } "` ;
1505
+ } else if ( symbolStr === 'Symbol()' ) {
1506
+ elementRef = `"${ containerName } " element` ;
1507
+ } else {
1508
+ const match = symbolStr . match ( / ^ S y m b o l \( ( .+ ) \) $ / ) ;
1509
+ elementRef = `"${ containerName } " element "${ match ? match [ 1 ] : symbolStr } "` ;
1510
+ }
1511
+ }
1512
+
1513
+ let msg = `The ${ elementRef } must be ` ;
1514
+
1515
+ const types = [ ] ;
1516
+ const instances = [ ] ;
1517
+ const other = [ ] ;
1518
+
1519
+ for ( const value of expected ) {
1520
+ assert ( typeof value === 'string' ,
1521
+ 'All expected entries have to be of type string' ) ;
1522
+ if ( ArrayPrototypeIncludes ( kTypes , value ) ) {
1523
+ ArrayPrototypePush ( types , StringPrototypeToLowerCase ( value ) ) ;
1524
+ } else if ( RegExpPrototypeExec ( classRegExp , value ) !== null ) {
1525
+ ArrayPrototypePush ( instances , value ) ;
1526
+ } else {
1527
+ assert ( value !== 'object' ,
1528
+ 'The value "object" should be written as "Object"' ) ;
1529
+ ArrayPrototypePush ( other , value ) ;
1530
+ }
1531
+ }
1532
+
1533
+ // Special handle `object` in case other instances are allowed to outline
1534
+ // the differences between each other.
1535
+ if ( instances . length > 0 ) {
1536
+ const pos = ArrayPrototypeIndexOf ( types , 'object' ) ;
1537
+ if ( pos !== - 1 ) {
1538
+ ArrayPrototypeSplice ( types , pos , 1 ) ;
1539
+ ArrayPrototypePush ( instances , 'Object' ) ;
1540
+ }
1541
+ }
1542
+
1543
+ if ( types . length > 0 ) {
1544
+ msg += `${ types . length > 1 ? 'one of type' : 'of type' } ${ formatList ( types , 'or' ) } ` ;
1545
+ if ( instances . length > 0 || other . length > 0 )
1546
+ msg += ' or ' ;
1547
+ }
1548
+
1549
+ if ( instances . length > 0 ) {
1550
+ msg += `an instance of ${ formatList ( instances , 'or' ) } ` ;
1551
+ if ( other . length > 0 )
1552
+ msg += ' or ' ;
1553
+ }
1554
+
1555
+ if ( other . length > 0 ) {
1556
+ if ( other . length > 1 ) {
1557
+ msg += `one of ${ formatList ( other , 'or' ) } ` ;
1558
+ } else {
1559
+ if ( StringPrototypeToLowerCase ( other [ 0 ] ) !== other [ 0 ] )
1560
+ msg += 'an ' ;
1561
+ msg += `${ other [ 0 ] } ` ;
1562
+ }
1563
+ }
1564
+
1565
+ msg += `. Received ${ determineSpecificType ( actual ) } ` ;
1566
+
1483
1567
return msg ;
1484
1568
} , TypeError , HideStackFramesError ) ;
1485
1569
E ( 'ERR_INVALID_CURSOR_POS' ,
0 commit comments