File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -167,4 +167,17 @@ describe("cloud/errors reportApiError", () => {
167167 expect ( ( ) => reportApiError ( "Weird failure" , "just a string" ) ) . toThrow ( CliRuntimeError ) ;
168168 expect ( errorBox ) . toHaveBeenCalledWith ( "Weird failure" , "just a string" , undefined ) ;
169169 } ) ;
170+
171+ it ( "names the network cause of a failed fetch on the third line, and nothing for a free-text cause" , ( ) => {
172+ const cause = Object . assign ( new Error ( "connect ETIMEDOUT 1.2.3.4:443" ) , { code : "ETIMEDOUT" } ) ;
173+ expect ( ( ) => reportApiError ( "Upload failed" , new TypeError ( "fetch failed" , { cause } ) ) ) . toThrow (
174+ CliRuntimeError ,
175+ ) ;
176+ expect ( errorBox ) . toHaveBeenLastCalledWith ( "Upload failed" , "fetch failed" , "code: ETIMEDOUT" ) ;
177+ const odd = Object . assign ( new Error ( "x" ) , { code : "see /Users/me/file.mp4" } ) ;
178+ expect ( ( ) =>
179+ reportApiError ( "Upload failed" , new TypeError ( "fetch failed" , { cause : odd } ) ) ,
180+ ) . toThrow ( CliRuntimeError ) ;
181+ expect ( errorBox ) . toHaveBeenLastCalledWith ( "Upload failed" , "fetch failed" , undefined ) ;
182+ } ) ;
170183} ) ;
Original file line number Diff line number Diff line change @@ -56,6 +56,14 @@ function hintCode(err: HyperframesApiError): string | undefined {
5656 * errors) so the user can recover without having to remember the
5757 * render_id.
5858 */
59+ /** `code: ETIMEDOUT` for a failed fetch, whose own message is only "fetch failed"; the cause names why. */
60+ function networkCode ( err : Error ) : string | undefined {
61+ const code = ( err . cause as { code ?: unknown } | undefined ) ?. code ;
62+ return typeof code === "string" && / ^ [ A - Z ] [ A - Z 0 - 9 _ ] { 2 , 40 } $ / . test ( code )
63+ ? `code: ${ code } `
64+ : undefined ;
65+ }
66+
5967// fallow-ignore-next-line complexity
6068export function reportApiError (
6169 stage : string ,
@@ -95,7 +103,7 @@ export function reportApiError(
95103 failCommand ( ) ;
96104 }
97105 if ( err instanceof Error ) {
98- errorBox ( stage , err . message , options . suggestion ) ;
106+ errorBox ( stage , err . message , options . suggestion ?? networkCode ( err ) ) ;
99107 failCommand ( ) ;
100108 }
101109 errorBox ( stage , String ( err ) , options . suggestion ) ;
You can’t perform that action at this time.
0 commit comments