From f6eaffe9d4f26523b066fe7db7d05d84300a979b Mon Sep 17 00:00:00 2001 From: German Lashevich Date: Tue, 23 Jul 2024 04:02:33 +0200 Subject: [PATCH] fix: avoid panic by checking response for nil Signed-off-by: German Lashevich --- pkg/vendir/fetch/githubrelease/sync.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/vendir/fetch/githubrelease/sync.go b/pkg/vendir/fetch/githubrelease/sync.go index 2b9c79c6..90e54682 100644 --- a/pkg/vendir/fetch/githubrelease/sync.go +++ b/pkg/vendir/fetch/githubrelease/sync.go @@ -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) }