Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid panic by checking response for nil #391

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading