Report a friendly error for snapshot branches missing on swift.org#547
Report a friendly error for snapshot branches missing on swift.org#547adityasingh2400 wants to merge 2 commits 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
| /// 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( |
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.
Per review, fold the SnapshotBranchNotFoundError mapping back into getSnapshotToolchains instead of a standalone devToolchains helper. Keep the branch-reconstruction round-trip test, which covers the part with real logic; the response-mapping tests are dropped because they relied on the extracted helper as their seam and the suite has no transport mock to drive the public method offline.
|
Done in de066ad. Inlined the 404 check straight into One heads-up on the tests: that helper was also the seam the unit tests used to exercise the 404 to If you would rather keep that path covered, I am happy to add a small mock-transport test that returns a 404 and asserts |
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