Make file download fail-safe and retry on transient errors#131
Open
jimexist wants to merge 1 commit into
Open
Conversation
A failed download crashed with IllegalArgumentException ("json string
can not be null or empty") because throwOnError passed an empty string
to JsonPath: for file downloads the response body is a Path, which
safeCastHttpBodyToString turned into "".
- Skip error-message parsing when the body is blank and catch any
JsonPath failure, falling back to "Unknown error, HTTP Status: <code>"
- Read Path response bodies so download errors surface the server's
actual error message
- Delete the file written by the ofFile body handler on non-200
responses instead of leaving the error payload as a translation file
- Retry downloads up to 3 times with linear backoff on IOException,
HTTP 429 and 5xx; fail fast on other 4xx
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Hi @jimexist , thanks for the PR. I will review and merge it later this week. 😊 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes a crash when a translation file download fails, and adds bounded retry for transient download errors.
Why
A failed download (e.g. an expired or forbidden S3 link) crashed the CLI with an unhelpful stack trace instead of a proper error message:
Root cause: for file downloads the response body is a
Path(fromBodyHandlers.ofFile), whichsafeCastHttpBodyToStringturned into"", andJsonPath.parse("")throws beforeSUPPRESS_EXCEPTIONScan apply. The same crash affected any endpoint returning an error with an empty body.Changes
throwOnErrornever crashes on unparseable bodies: error-message extraction skips blank bodies and catches any JsonPath failure, falling back toUnknown error, HTTP Status: <code>.Pathbodies are read for error messages: failed downloads now surface the server's actual error message (e.g.link expired) instead of a generic one.BodyHandlers.ofFile(..., TRUNCATE_EXISTING)writes the error response to the target translation file on failure; it is now deleted instead of being left behind masquerading as a translation file.IOException, HTTP 429, and 5xx. Other 4xx (403/404) fail fast since retrying can't help.Notes for reviewers
ApiRequestExceptionwith the extracted (or fallback) message.Tests
Added coverage in
SimpleLocalizeClientTest(mock-server based):ApiRequestException, no leftover file (the reported crash)$.msgFull suite passes: 88 tests, 0 failures.
🤖 Generated with Claude Code