Skip to content

Commit

Permalink
fix: avoid panic by checking response for nil
Browse files Browse the repository at this point in the history
Signed-off-by: German Lashevich <[email protected]>
  • Loading branch information
Zebradil committed Jul 23, 2024
1 parent 1ccbd25 commit f6eaffe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/vendir/fetch/githubrelease/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ func (d Sync) fetchTagSelection() (string, error) {
tagList, resp, err := d.client.Repositories.ListTags(context.Background(), ownerName, repoName, &listOpt)
if err != nil {
errMsg := err.Error()
switch resp.StatusCode {
case 401, 403:
hintMsg := "(hint: consider setting VENDIR_GITHUB_API_TOKEN env variable to increase API rate limits)"
bs, _ := io.ReadAll(resp.Body)
errMsg += fmt.Sprintf(" %s (body: '%s')", hintMsg, bs)
if resp != nil {
switch resp.StatusCode {
case 401, 403:
hintMsg := "(hint: consider setting VENDIR_GITHUB_API_TOKEN env variable to increase API rate limits)"
bs, _ := io.ReadAll(resp.Body)
errMsg += fmt.Sprintf(" %s (body: '%s')", hintMsg, bs)
}
}
return "", fmt.Errorf("Downloading tags info: %s", errMsg)
}
Expand Down

0 comments on commit f6eaffe

Please sign in to comment.