@@ -446,10 +446,13 @@ function outputFormatterError(err: any): string {
446446 for ( const [ key , value ] of Object . entries ( err . metadata ) ) {
447447 output += `${ indent } ${ key } \t${ value } \n` ;
448448 }
449+ output += `${ indent } timestamp\t${ err . timestamp } \n` ;
449450 } else {
450451 output += '\n' ;
451452 }
452- output += `${ indent } timestamp\t${ err . timestamp } \n` ;
453+ if ( err . stack ) {
454+ output += `${ indent } stack: ${ JSON . stringify ( err . stack ) } \n` ;
455+ }
453456 output += `${ indent } cause: ` ;
454457 err = err . cause ;
455458 } else if ( err instanceof ErrorPolykey ) {
@@ -483,44 +486,7 @@ function outputFormatterError(err: any): string {
483486 break ;
484487 }
485488 } else {
486- let errorName = '' ;
487- switch ( typeof err ) {
488- case 'boolean' :
489- case 'number' :
490- case 'string' :
491- case 'bigint' :
492- case 'symbol' :
493- errorName = `Literal: ${ String ( err ) } ` ;
494- break ;
495- case 'object' :
496- if ( err == null ) break ;
497- if ( 'name' in err && typeof err . name === 'string' ) {
498- errorName = err . name ;
499- break ;
500- }
501- if ( err . constructor ?. name != null ) {
502- if ( err . constructor . name === 'Object' ) {
503- // If the constructor name is Object, then the error is a JSON
504- // object.
505- errorName = `Object: ${ JSON . stringify ( err ) } ` ;
506- } else {
507- // Otherwise, it is a regular object.
508- errorName = `Object: ${ err . constructor . name } ` ;
509- }
510- break ;
511- }
512- break ;
513- }
514- if ( errorName === '' ) {
515- try {
516- errorName = `Value: ${ err } ` ;
517- } catch ( e ) {
518- if ( e instanceof TypeError ) errorName = 'Value: null' ;
519- else throw e ;
520- }
521- }
522-
523- output += errorName ;
489+ output += composeErrorMessage ( err ) ;
524490 if ( err . message && err . message !== '' ) {
525491 output += `: ${ err . message } ` ;
526492 }
@@ -532,6 +498,39 @@ function outputFormatterError(err: any): string {
532498 return output ;
533499}
534500
501+ function composeErrorMessage ( error : any ) {
502+ switch ( typeof error ) {
503+ case 'boolean' :
504+ case 'number' :
505+ case 'string' :
506+ case 'bigint' :
507+ case 'symbol' :
508+ return `Thrown non-error literal '${ String ( error ) } '` ;
509+ case 'object' :
510+ if ( error == null ) break ;
511+ if ( 'name' in error && typeof error . name === 'string' ) {
512+ return `Thrown non-error '${ error . name } '` ;
513+ }
514+ if ( error . constructor ?. name != null ) {
515+ if ( error . constructor . name === 'Object' ) {
516+ // If the constructor name is Object, then the error is a JSON
517+ // object.
518+ return `Thrown non-error JSON '${ JSON . stringify ( error ) } '` ;
519+ } else {
520+ // Otherwise, it is a regular object.
521+ return `Thrown non-error object '${ error . constructor . name } '` ;
522+ }
523+ }
524+ break ;
525+ }
526+ try {
527+ return `Thrown non-error value '${ error } '` ;
528+ } catch ( e ) {
529+ if ( e instanceof TypeError ) return `Thrown non-error value 'null'` ;
530+ else throw e ;
531+ }
532+ }
533+
535534/**
536535 * CLI Authentication Retry Loop
537536 * Retries unary calls on attended authentication errors
@@ -633,6 +632,7 @@ export {
633632 outputFormatterDict ,
634633 outputFormatterJson ,
635634 outputFormatterError ,
635+ composeErrorMessage ,
636636 retryAuthentication ,
637637 remoteErrorCause ,
638638 encodeEscapedWrapped ,
0 commit comments