Skip to content

Commit a910e93

Browse files
authored
chore: improve error message around gitaskpass failures (#9407)
1 parent 2399063 commit a910e93

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

cli/gitaskpass.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ func (r *RootCmd) gitAskpass() *clibase.Cmd {
4444
if errors.As(err, &apiError) && apiError.StatusCode() == http.StatusNotFound {
4545
// This prevents the "Run 'coder --help' for usage"
4646
// message from occurring.
47-
cliui.Errorf(inv.Stderr, "%s\n", apiError.Message)
47+
lines := []string{apiError.Message}
48+
if apiError.Detail != "" {
49+
lines = append(lines, apiError.Detail)
50+
}
51+
cliui.Warn(inv.Stderr, "Coder was unable to handle this git request. The default git behavior will be used instead.",
52+
lines...,
53+
)
4854
return cliui.Canceled
4955
}
5056
return xerrors.Errorf("get git token: %w", err)

coderd/workspaceagents.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1996,8 +1996,17 @@ func (api *API) workspaceAgentsGitAuth(rw http.ResponseWriter, r *http.Request)
19961996
gitAuthConfig = gitAuth
19971997
}
19981998
if gitAuthConfig == nil {
1999+
detail := "No git providers are configured."
2000+
if len(api.GitAuthConfigs) > 0 {
2001+
regexURLs := make([]string, 0, len(api.GitAuthConfigs))
2002+
for _, gitAuth := range api.GitAuthConfigs {
2003+
regexURLs = append(regexURLs, fmt.Sprintf("%s=%q", gitAuth.ID, gitAuth.Regex.String()))
2004+
}
2005+
detail = fmt.Sprintf("The configured git provider have regex filters that do not match the git url. Provider url regexs: %s", strings.Join(regexURLs, ","))
2006+
}
19992007
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
2000-
Message: fmt.Sprintf("No git provider found for URL %q", gitURL),
2008+
Message: fmt.Sprintf("No matching git provider found in Coder for the url %q.", gitURL),
2009+
Detail: detail,
20012010
})
20022011
return
20032012
}

0 commit comments

Comments
 (0)