Commit 04f5add
authored
fix: Prevent panic on non-retryable download errors (#619)
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
#### Summary
Fixes a panic in `downloadFile` caused by an unsafe type assertion (`err.(retry.Error)`) when the retry library returns a plain error.
Changes included:
- Replace string-based retry classification with sentinel errors + `errors.Is`
- Remove the unsafe type assertion path and return clean errors for both retry and non-retry failures
- Add regression tests that verify `downloadFile` does not panic on:
- invalid/non-retryable request errors
- 404 responses
In `github.com/avast/retry-go/v5`, it can return a non-retry.Error in these cases:
1. `LastErrorOnly(true)` is set. It returns the last underlying error directly.
2. Context is already done before retries start. Do() returns `context.Cause(ctx)` directly (often `context.Canceled` / `context.DeadlineExceeded`, which can be `*errors.errorString`).
3. Attempts(0) / UntilSucceeded() mode. If the function returns an unrecoverable error (`retry.Unrecoverable(...)`) or `RetryIf` says “don’t retry”, it returns that raw error directly.
If context is canceled in this mode (and `WrapContextErrorWithLastError(false)`), it also returns raw context error.
---1 parent 28543e4 commit 04f5add
2 files changed
Lines changed: 56 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
343 | 346 | | |
344 | 347 | | |
345 | 348 | | |
346 | | - | |
| 349 | + | |
347 | 350 | | |
348 | 351 | | |
349 | 352 | | |
| |||
366 | 369 | | |
367 | 370 | | |
368 | 371 | | |
369 | | - | |
| 372 | + | |
370 | 373 | | |
371 | 374 | | |
372 | | - | |
| 375 | + | |
373 | 376 | | |
374 | 377 | | |
375 | 378 | | |
| |||
398 | 401 | | |
399 | 402 | | |
400 | 403 | | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
| 404 | + | |
| 405 | + | |
405 | 406 | | |
406 | 407 | | |
407 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
13 | 61 | | |
14 | 62 | | |
15 | 63 | | |
| |||
0 commit comments