Skip to content

Commit

Permalink
Merge pull request #391 from Zebradil/389-fix-panic
Browse files Browse the repository at this point in the history
fix: avoid panic by checking response for nil
  • Loading branch information
joaopapereira authored Jul 24, 2024
2 parents 1ccbd25 + a1f83af commit 0c8f01a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 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 Expand Up @@ -433,7 +435,7 @@ func (d Sync) authToken() (string, error) {
}
}

return token, nil
return strings.TrimSpace(token), nil
}

type ReleaseAPI struct {
Expand Down

0 comments on commit 0c8f01a

Please sign in to comment.