Skip to content

Commit c0f116c

Browse files
authored
chore: bubble up errors when downloading credential helper fails (#845)
Signed-off-by: Donnie Adams <[email protected]>
1 parent dbf46d1 commit c0f116c

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

pkg/repos/get.go

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func (m *Manager) deferredSetUpCredentialHelpers(ctx context.Context, cliCfg *co
146146
}
147147

148148
tool := types.Tool{
149+
ToolDef: types.ToolDef{
150+
Parameters: types.Parameters{
151+
Name: "gptscript-credential-helpers",
152+
},
153+
},
149154
Source: types.ToolSource{
150155
Repo: &types.Repo{
151156
Root: runtimeEnv.VarOrDefault("GPTSCRIPT_CRED_HELPERS_ROOT", "https://github.com/gptscript-ai/gptscript-credential-helpers.git"),

pkg/repos/runtimes/golang/golang.go

+21-16
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,26 @@ type tag struct {
9797
}
9898

9999
func GetLatestTag(tool types.Tool) (string, error) {
100-
r, ok := getLatestRelease(tool)
100+
r, ok, err := getLatestRelease(tool)
101+
if err != nil {
102+
return "", err
103+
}
104+
101105
if !ok {
102106
return "", fmt.Errorf("failed to get latest release for %s", tool.Name)
103107
}
108+
104109
return r.label, nil
105110
}
106111

107-
func getLatestRelease(tool types.Tool) (*release, bool) {
112+
func getLatestRelease(tool types.Tool) (*release, bool, error) {
108113
if tool.Source.Repo == nil || !strings.HasPrefix(tool.Source.Repo.Root, "https://github.com/") {
109-
return nil, false
114+
return nil, false, nil
110115
}
111116

112117
parts := strings.Split(strings.TrimPrefix(strings.TrimSuffix(tool.Source.Repo.Root, ".git"), "https://"), "/")
113118
if len(parts) != 3 {
114-
return nil, false
119+
return nil, false, fmt.Errorf("invalid GitHub URL: %s", tool.Source.Repo.Root)
115120
}
116121

117122
client := http.Client{
@@ -124,41 +129,39 @@ func getLatestRelease(tool types.Tool) (*release, bool) {
124129

125130
resp, err := client.Get(fmt.Sprintf("https://api.github.com/repos/%s/%s/tags", account, repo))
126131
if err != nil {
127-
// ignore error
128-
return nil, false
132+
return nil, false, fmt.Errorf("failed to get tags: %w", err)
129133
}
130134
defer resp.Body.Close()
131135
if resp.StatusCode != http.StatusOK {
132-
return nil, false
136+
return nil, false, fmt.Errorf("unexpected status when getting tags: %s", resp.Status)
133137
}
134138

135139
var tags []tag
136140
if err := json.NewDecoder(resp.Body).Decode(&tags); err != nil {
137-
return nil, false
141+
return nil, false, fmt.Errorf("failed to decode GitHub tags: %w", err)
138142
}
139143
for _, tag := range tags {
140144
if tag.Commit.Sha == tool.Source.Repo.Revision {
141145
return &release{
142146
account: account,
143147
repo: repo,
144148
label: tag.Name,
145-
}, true
149+
}, true, nil
146150
}
147151
}
148152

149153
resp, err = client.Get(fmt.Sprintf("https://github.com/%s/%s/releases/latest", account, repo))
150154
if err != nil {
151-
// ignore error
152-
return nil, false
155+
return nil, false, fmt.Errorf("failed to get latest release: %w", err)
153156
}
154157
defer resp.Body.Close()
155158
if resp.StatusCode != http.StatusFound {
156-
return nil, false
159+
return nil, false, fmt.Errorf("unexpected status when getting latest release: %s", resp.Status)
157160
}
158161

159162
target := resp.Header.Get("Location")
160163
if target == "" {
161-
return nil, false
164+
return nil, false, nil
162165
}
163166

164167
parts = strings.Split(target, "/")
@@ -168,7 +171,7 @@ func getLatestRelease(tool types.Tool) (*release, bool) {
168171
account: account,
169172
repo: repo,
170173
label: label,
171-
}, true
174+
}, true, nil
172175
}
173176

174177
func get(ctx context.Context, url string) (*http.Response, error) {
@@ -249,7 +252,8 @@ func (r *Runtime) Binary(ctx context.Context, tool types.Tool, _, toolSource str
249252
return false, nil, nil
250253
}
251254

252-
rel, ok := getLatestRelease(tool)
255+
// ignore the error
256+
rel, ok, _ := getLatestRelease(tool)
253257
if !ok {
254258
return false, nil, nil
255259
}
@@ -286,7 +290,8 @@ func (r *Runtime) DownloadCredentialHelper(ctx context.Context, tool types.Tool,
286290
return nil
287291
}
288292

289-
rel, ok := getLatestRelease(tool)
293+
// ignore the error
294+
rel, ok, _ := getLatestRelease(tool)
290295
if !ok {
291296
return fmt.Errorf("failed to find %s release", r.ID())
292297
}

0 commit comments

Comments
 (0)