@@ -88,6 +88,7 @@ const {
88
88
StringPrototypePadEnd,
89
89
StringPrototypePadStart,
90
90
StringPrototypeRepeat,
91
+ StringPrototypeReplace,
91
92
StringPrototypeReplaceAll,
92
93
StringPrototypeSlice,
93
94
StringPrototypeSplit,
@@ -733,6 +734,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
733
734
} while ( ++ depth !== 3 ) ;
734
735
}
735
736
737
+ /** @type {(constructor: string, tag: string, fallback: string, size?: string) => string } */
736
738
function getPrefix ( constructor , tag , fallback , size = '' ) {
737
739
if ( constructor === null ) {
738
740
if ( tag !== '' && fallback !== tag ) {
@@ -1316,11 +1318,20 @@ function getStackFrames(ctx, err, stack) {
1316
1318
return frames ;
1317
1319
}
1318
1320
1321
+ /** @type {(stack: string, constructor: string | null, name: unknown, tag: string) => string } */
1319
1322
function improveStack ( stack , constructor , name , tag ) {
1320
1323
// A stack trace may contain arbitrary data. Only manipulate the output
1321
1324
// for "regular errors" (errors that "look normal") for now.
1322
1325
let len = name . length ;
1323
1326
1327
+ if ( typeof name !== 'string' ) {
1328
+ stack = StringPrototypeReplace (
1329
+ stack ,
1330
+ `${ name } ` ,
1331
+ `${ name } [${ StringPrototypeSlice ( getPrefix ( constructor , tag , 'Error' ) , 0 , - 1 ) } ]` ,
1332
+ ) ;
1333
+ }
1334
+
1324
1335
if ( constructor === null ||
1325
1336
( StringPrototypeEndsWith ( name , 'Error' ) &&
1326
1337
StringPrototypeStartsWith ( stack , name ) &&
@@ -1353,8 +1364,8 @@ function removeDuplicateErrorKeys(ctx, keys, err, stack) {
1353
1364
if ( ! ctx . showHidden && keys . length !== 0 ) {
1354
1365
for ( const name of [ 'name' , 'message' , 'stack' ] ) {
1355
1366
const index = ArrayPrototypeIndexOf ( keys , name ) ;
1356
- // Only hide the property in case it's part of the original stack
1357
- if ( index !== - 1 && StringPrototypeIncludes ( stack , err [ name ] ) ) {
1367
+ // Only hide the property if it's a string and if it's part of the original stack
1368
+ if ( index !== - 1 && ( typeof err [ name ] !== 'string' || StringPrototypeIncludes ( stack , err [ name ] ) ) ) {
1358
1369
ArrayPrototypeSplice ( keys , index , 1 ) ;
1359
1370
}
1360
1371
}
@@ -1414,7 +1425,7 @@ function safeGetCWD() {
1414
1425
}
1415
1426
1416
1427
function formatError ( err , constructor , tag , ctx , keys ) {
1417
- const name = err . name != null ? String ( err . name ) : 'Error' ;
1428
+ const name = err . name != null ? err . name : 'Error' ;
1418
1429
let stack = getStackString ( err ) ;
1419
1430
1420
1431
removeDuplicateErrorKeys ( ctx , keys , err , stack ) ;
0 commit comments