Skip to content

Commit f6eaffe

Browse files
committed
fix: avoid panic by checking response for nil
Signed-off-by: German Lashevich <german.lashevich@gmail.com>
1 parent 1ccbd25 commit f6eaffe

File tree

1 file changed

+7
-5
lines changed
  • pkg/vendir/fetch/githubrelease

1 file changed

+7
-5
lines changed

pkg/vendir/fetch/githubrelease/sync.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,13 @@ func (d Sync) fetchTagSelection() (string, error) {
244244
tagList, resp, err := d.client.Repositories.ListTags(context.Background(), ownerName, repoName, &listOpt)
245245
if err != nil {
246246
errMsg := err.Error()
247-
switch resp.StatusCode {
248-
case 401, 403:
249-
hintMsg := "(hint: consider setting VENDIR_GITHUB_API_TOKEN env variable to increase API rate limits)"
250-
bs, _ := io.ReadAll(resp.Body)
251-
errMsg += fmt.Sprintf(" %s (body: '%s')", hintMsg, bs)
247+
if resp != nil {
248+
switch resp.StatusCode {
249+
case 401, 403:
250+
hintMsg := "(hint: consider setting VENDIR_GITHUB_API_TOKEN env variable to increase API rate limits)"
251+
bs, _ := io.ReadAll(resp.Body)
252+
errMsg += fmt.Sprintf(" %s (body: '%s')", hintMsg, bs)
253+
}
252254
}
253255
return "", fmt.Errorf("Downloading tags info: %s", errMsg)
254256
}

0 commit comments

Comments
 (0)