Handle invalid source control URLs in registry identity lookup #9444
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.
Summary
Add validation for source control URLs at multiple levels to handle malformed URLs gracefully.
Problem
When macOS
git-credential-osxkeychainfails to find credentials, it outputs error messages that can get concatenated with the original URL:These malformed URLs were being sent to the registry server, causing errors. This was observed in the Tuist registry where we added server-side validation to return HTTP 400 for invalid URLs (see tuist/tuist#8829).
Solution
1. Add
isValidproperty toSourceControlURLValid source control URLs:
user@host:path)2. Early validation in
mapRegistryIdentityThis validates URLs before making any HTTP requests to the registry.
3. Handle HTTP 400 from registry servers
If a URL passes client validation but the server still rejects it with 400 Bad Request, we throw the same specific error.
Changes
Sources/Basics/SourceControlURL.swift: AddedisValidcomputed propertySources/Workspace/Workspace+Registry.swift: Added early URL validationSources/PackageRegistry/RegistryClient.swift:invalidSourceControlURLerror caselookupIdentitiesTests/BasicsTests/SourceControlURLTests.swift: Added tests for URL validationTests/PackageRegistryTests/RegistryClientTests.swift: Added test for 400 handlingTest Plan
SourceControlURLTests- Tests forisValidproperty (4 tests)LookupIdentities- Tests for registry client including 400 handling (6 tests)Related
🤖 Generated with Claude Code