Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/gitstore/remote_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ func remoteFailure(diagnostic, code, message string) error {
return contract.Fail("GIT_AUTH_FAILED", "Code-service credential was rejected; update the credential.", 401)
}
// Code hosts answer "not found" both for missing repositories and for private
// ones the credential cannot see, so the message names both causes.
if httpStatus(text, "404") || strings.Contains(text, "repository not found") || (strings.Contains(text, "repository '") && strings.Contains(text, "' not found")) {
// ones the credential cannot see, so the message names both causes. An
// anonymous request the host answers with a credential prompt means the same.
if httpStatus(text, "404") || strings.Contains(text, "could not read username") || strings.Contains(text, "repository not found") || (strings.Contains(text, "repository '") && strings.Contains(text, "' not found")) {
return contract.Fail("GIT_REPOSITORY_UNAVAILABLE", "Repository not found, or the code-service credential used cannot see it.", 404)
}
return contract.Fail(code, message, 503)
Expand Down
9 changes: 5 additions & 4 deletions internal/gitstore/remote_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ func TestRemoteFailureNamesMissingOrInvisibleRepositories(t *testing.T) {
for diagnostic, want := range map[string]string{
"remote: Repository not found.\nfatal: repository 'https://code.example.com/a/b.git/' not found": "GIT_REPOSITORY_UNAVAILABLE",
"fatal: unable to access 'https://x/a/b.git/': The requested URL returned error: 404": "GIT_REPOSITORY_UNAVAILABLE",
"error: 404 Not Found": "GIT_REPOSITORY_UNAVAILABLE",
"fatal: Authentication failed for 'https://x'": "GIT_AUTH_FAILED",
"error: 403 Forbidden": "GIT_ACCESS_DENIED",
"fatal: unable to connect": "GIT_FETCH_FAILED",
"error: 404 Not Found": "GIT_REPOSITORY_UNAVAILABLE",
"fatal: could not read Username for 'https://github.com': terminal prompts disabled": "GIT_REPOSITORY_UNAVAILABLE",
"fatal: Authentication failed for 'https://x'": "GIT_AUTH_FAILED",
"error: 403 Forbidden": "GIT_ACCESS_DENIED",
"fatal: unable to connect": "GIT_FETCH_FAILED",
} {
var ce *contract.Error
if err := remoteFailure(diagnostic, "GIT_FETCH_FAILED", "fetch failed"); !errors.As(err, &ce) || ce.Code != want {
Expand Down
Loading