Skip to content

Commit 37b36f0

Browse files
authored
Check all errors in chain for auth error not just top level (#71)
1 parent c7b4555 commit 37b36f0

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

clients/git/client.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package git
22

33
import (
44
"errors"
5-
"fmt"
65
"os"
76
"os/exec"
87
"regexp"
@@ -53,8 +52,6 @@ func Clone(url, targetDir string) error {
5352
// Include the git output in the error message
5453
return clierrors.WrapError("git clone failed: "+string(output), err)
5554
}
56-
// Print output on success
57-
fmt.Print(string(output))
5855
return nil
5956
}
6057

cmd/app/helper.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app
22

33
import (
4+
stderrors "errors"
45
"fmt"
56
"os"
67
"os/exec"
@@ -94,13 +95,12 @@ func cloneRepository(sshURL, httpsURL, targetDir string) (string, error) {
9495
}
9596

9697
// isGitAuthError checks if the error is related to git authentication/permission issues
98+
// It checks all wrapped errors in the chain, not just the top-level error
9799
func isGitAuthError(err error) bool {
98100
if err == nil {
99101
return false
100102
}
101103

102-
errMsg := strings.ToLower(err.Error())
103-
104104
// Common git authentication error patterns
105105
authErrorPatterns := []string{
106106
"repository not found", // Catches "ERROR: Repository not found."
@@ -113,9 +113,13 @@ func isGitAuthError(err error) bool {
113113
"fatal: unable to access",
114114
}
115115

116-
for _, pattern := range authErrorPatterns {
117-
if strings.Contains(errMsg, pattern) {
118-
return true
116+
// Check all errors in the chain
117+
for e := err; e != nil; e = stderrors.Unwrap(e) {
118+
errMsg := strings.ToLower(e.Error())
119+
for _, pattern := range authErrorPatterns {
120+
if strings.Contains(errMsg, pattern) {
121+
return true
122+
}
119123
}
120124
}
121125

0 commit comments

Comments
 (0)