@@ -1287,8 +1287,14 @@ function identicalSequenceRange(a, b) {
12871287 return { len : 0 , offset : 0 } ;
12881288}
12891289
1290- function getStackString ( error ) {
1291- return error . stack ? String ( error . stack ) : ErrorPrototypeToString ( error ) ;
1290+ function getStackString ( ctx , error ) {
1291+ if ( error . stack ) {
1292+ if ( typeof error . stack === 'string' ) {
1293+ return error . stack ;
1294+ }
1295+ return formatValue ( ctx , error . stack ) ;
1296+ }
1297+ return ErrorPrototypeToString ( error ) ;
12921298}
12931299
12941300function getStackFrames ( ctx , err , stack ) {
@@ -1303,7 +1309,7 @@ function getStackFrames(ctx, err, stack) {
13031309
13041310 // Remove stack frames identical to frames in cause.
13051311 if ( cause != null && isError ( cause ) ) {
1306- const causeStack = getStackString ( cause ) ;
1312+ const causeStack = getStackString ( ctx , cause ) ;
13071313 const causeStackStart = StringPrototypeIndexOf ( causeStack , '\n at' ) ;
13081314 if ( causeStackStart !== - 1 ) {
13091315 const causeFrames = StringPrototypeSplit ( StringPrototypeSlice ( causeStack , causeStackStart + 1 ) , '\n' ) ;
@@ -1324,6 +1330,7 @@ function improveStack(stack, constructor, name, tag) {
13241330 // for "regular errors" (errors that "look normal") for now.
13251331 let len = name . length ;
13261332
1333+ console . error ( name , typeof name )
13271334 if ( typeof name !== 'string' ) {
13281335 stack = StringPrototypeReplace (
13291336 stack ,
@@ -1425,8 +1432,8 @@ function safeGetCWD() {
14251432}
14261433
14271434function formatError ( err , constructor , tag , ctx , keys ) {
1428- const name = err . name != null ? err . name : 'Error' ;
1429- let stack = getStackString ( err ) ;
1435+ const name = err . name != null ? String ( err . name ) : 'Error' ;
1436+ let stack = getStackString ( ctx , err ) ;
14301437
14311438 removeDuplicateErrorKeys ( ctx , keys , err , stack ) ;
14321439
0 commit comments