Report a friendly error for snapshot branches missing on swift.org#547
Open
adityasingh2400 wants to merge 1 commit into
Open
Report a friendly error for snapshot branches missing on swift.org#547adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
When a snapshot branch isn't published on swift.org, the dev-toolchains
endpoint responds with a 404. swiftly was forwarding that straight
through `response.ok.body.json`, so `list-available 9.9-snapshot`,
`install 6.3-snapshot`, and snapshot updates surfaced the raw OpenAPI
failure ("Unexpected response, expected status code: ok, response:
undocumented(statusCode: 404, ...)") instead of something actionable.
`install`, `list-available`, and `update` already catch
`SwiftlyHTTPClient.SnapshotBranchNotFoundError` and turn it into a clear
message, but nothing ever threw it, so those catch blocks were dead. Map
a 404 from `listDevToolchains` to that error, reconstructing the branch
from the requested `SourceBranch` so the message names the branch the
user asked for. Non-404 responses (for example a 5xx) keep propagating
as before so a server error isn't misreported as a missing branch.
Resolves: swiftlang#539
etcwilde
reviewed
May 28, 2026
| /// supported `main` and previous x.y releases). That response is surfaced as a typed | ||
| /// `SnapshotBranchNotFoundError` so callers can present an actionable message instead of the | ||
| /// raw, low-level HTTP failure. | ||
| static func devToolchains( |
Member
There was a problem hiding this comment.
It looks like this function is just wrapping an if-statement. Lets inline the if-statement back up into the original function.
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.
When you ask swiftly for a snapshot branch that isn't published on swift.org, you currently get a raw, low-level HTTP error rather than something you can act on:
The same thing happens for
swiftly install <branch>-snapshotand when updating a snapshot whose branch has aged out.The root cause is that
HTTPRequestExecutorImpl.getSnapshotToolchainsforwarded the response straight throughresponse.ok.body.json. swift.org returns a 404 for the dev-toolchains endpoint when the branch doesn't exist (or is older than the supportedmainand previous x.y releases), and.okthen throws the generic OpenAPI runtime error.Interestingly,
install,list-available, andupdatealreadycatch SwiftlyHTTPClient.SnapshotBranchNotFoundErrorand turn it into a clear, actionable message. But nothing ever threw that error, so all three catch blocks were dead code.This change detects the 404 from
listDevToolchainsand throwsSnapshotBranchNotFoundError, reconstructing the branch from theSourceBranchthat was requested so the message names the branch the user actually typed. The reconstruction is the inverse of theSourceBranchmapping already done ingetSnapshotToolchains. Non-404 responses (for example a 5xx server error) keep propagating as before, so a transient server problem is not misreported as a missing branch.With the fix, the same command now reports:
Verification: added
SnapshotBranchNotFoundTests, which feeds a synthetic 404listDevToolchainsresponse through the response handler and asserts it maps toSnapshotBranchNotFoundErrorwith the correct branch (bothmainand a release branch), that a 200 still returns the toolchains untouched, that a 500 is not reported as a missing branch, and that theSourceBranchto branch reconstruction round-trips. The new tests fail before the change (the raw 404 error escapes) and pass after. The rest of the suite (171 tests across 21 suites, excluding the network-taggedHTTPClientTests) continues to pass, and swiftformat reports no changes for the touched files.Resolves #539