File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,10 +88,11 @@ describe("error helpers", () => {
8888 expect ( formatted ) . toBe ( "error A | error B" ) ;
8989 } ) ;
9090
91- it ( "dedupes causes whose message repeats the parent (e.g. FailoverError wrapping)" , ( ) => {
92- const inner = new Error ( 'No API key found for provider "openai-codex".' ) ;
91+ it ( "dedupes repeated cause messages while preserving deeper distinct causes" , ( ) => {
92+ const rootCause = new Error ( "provider auth lookup failed" ) ;
93+ const inner = new Error ( 'No API key found for provider "openai-codex".' , { cause : rootCause } ) ;
9394 const wrapper = new Error ( inner . message , { cause : inner } ) ;
94- expect ( formatErrorMessage ( wrapper ) ) . toBe ( inner . message ) ;
95+ expect ( formatErrorMessage ( wrapper ) ) . toBe ( ` ${ inner . message } | ${ rootCause . message } ` ) ;
9596 } ) ;
9697
9798 it ( "redacts sensitive tokens from formatted error messages" , ( ) => {
Original file line number Diff line number Diff line change @@ -74,18 +74,20 @@ export function formatErrorMessage(err: unknown): string {
7474 const seen = new Set < unknown > ( [ err ] ) ;
7575 // Skip causes that repeat a message already emitted (e.g. coerceToFailoverError).
7676 const seenMessages = new Set < string > ( [ formatted ] ) ;
77+ const appendCauseMessage = ( message : string ) : void => {
78+ if ( ! message || seenMessages . has ( message ) ) {
79+ return ;
80+ }
81+ formatted += ` | ${ message } ` ;
82+ seenMessages . add ( message ) ;
83+ } ;
7784 while ( cause && ! seen . has ( cause ) ) {
7885 seen . add ( cause ) ;
7986 if ( cause instanceof Error ) {
80- if ( cause . message && ! seenMessages . has ( cause . message ) ) {
81- formatted += ` | ${ cause . message } ` ;
82- seenMessages . add ( cause . message ) ;
83- }
87+ appendCauseMessage ( cause . message ) ;
8488 cause = cause . cause ;
8589 } else if ( typeof cause === "string" ) {
86- if ( ! seenMessages . has ( cause ) ) {
87- formatted += ` | ${ cause } ` ;
88- }
90+ appendCauseMessage ( cause ) ;
8991 break ;
9092 } else {
9193 break ;
You can’t perform that action at this time.
0 commit comments