@@ -177,6 +177,18 @@ export function clearTimeoutSignal(signal?: AbortSignal): void {
177
177
}
178
178
}
179
179
180
+ function handleTimeoutError (
181
+ spinner : { fail : ( text : string ) => void } ,
182
+ timeoutSeconds ?: number ,
183
+ url ?: string ,
184
+ ) : void {
185
+ const urlText = url ? ` for: ${ colors . red ( url ) } ` : "" ;
186
+ spinner . fail ( `Request timed out after ${ timeoutSeconds } seconds${ urlText } .` ) ;
187
+ console . error (
188
+ "Try increasing the timeout with --timeout option or check network connectivity." ,
189
+ ) ;
190
+ }
191
+
180
192
function wrapDocumentLoaderWithTimeout (
181
193
loader : DocumentLoader ,
182
194
timeoutSeconds ?: number ,
@@ -185,7 +197,9 @@ function wrapDocumentLoaderWithTimeout(
185
197
186
198
return ( url : string , options ?) => {
187
199
const signal = createTimeoutSignal ( timeoutSeconds ) ;
188
- return loader ( url , { ...options , signal } ) ;
200
+ return loader ( url , { ...options , signal } ) . finally ( ( ) =>
201
+ clearTimeoutSignal ( signal )
202
+ ) ;
189
203
} ;
190
204
}
191
205
@@ -345,10 +359,7 @@ export const command = new Command()
345
359
} ) ;
346
360
} catch ( error ) {
347
361
if ( error instanceof Error && error . message . includes ( "timed out" ) ) {
348
- spinner . fail ( `Request timed out after ${ options . timeout } seconds.` ) ;
349
- console . error (
350
- "Try increasing the timeout with --timeout option or check network connectivity." ,
351
- ) ;
362
+ handleTimeoutError ( spinner , options . timeout , url ) ;
352
363
} else {
353
364
spinner . fail ( `Failed to fetch object: ${ colors . red ( url ) } .` ) ;
354
365
if ( authLoader == null ) {
@@ -395,10 +406,7 @@ export const command = new Command()
395
406
} catch ( error ) {
396
407
logger . error ( "Failed to complete the traversal: {error}" , { error } ) ;
397
408
if ( error instanceof Error && error . message . includes ( "timed out" ) ) {
398
- spinner . fail ( `Request timed out after ${ options . timeout } seconds.` ) ;
399
- console . error (
400
- "Try increasing the timeout with --timeout option or check network connectivity." ,
401
- ) ;
409
+ handleTimeoutError ( spinner , options . timeout ) ;
402
410
} else {
403
411
spinner . fail ( "Failed to complete the traversal." ) ;
404
412
if ( authLoader == null ) {
@@ -432,14 +440,7 @@ export const command = new Command()
432
440
} ,
433
441
) . catch ( ( error ) => {
434
442
if ( error instanceof Error && error . message . includes ( "timed out" ) ) {
435
- spinner . fail (
436
- `Request timed out after ${ options . timeout } seconds for: ${
437
- colors . red ( url )
438
- } .`,
439
- ) ;
440
- console . error (
441
- "Try increasing the timeout with --timeout option or check network connectivity." ,
442
- ) ;
443
+ handleTimeoutError ( spinner , options . timeout , url ) ;
443
444
}
444
445
throw error ;
445
446
} ) ,
0 commit comments