From cfe707e522bec0699d43e18ac066b4a1ebab9071 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Wed, 21 May 2025 19:45:23 +0000 Subject: [PATCH] Fix potential nil pointer dereference Signed-off-by: Gabriel Adrian Samfira --- util/github/client.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util/github/client.go b/util/github/client.go index f25329c7..a553e1d8 100644 --- a/util/github/client.go +++ b/util/github/client.go @@ -240,8 +240,13 @@ func (g *githubClient) ListEntityRunnerApplicationDownloads(ctx context.Context) } func parseError(response *github.Response, err error) error { - slog.Debug("parsing error", "status_code", response.StatusCode, "response", response, "error", err) - switch response.StatusCode { + var statusCode int + if response != nil { + statusCode = response.StatusCode + } + + slog.Debug("parsing error", "status_code", statusCode, "response", response, "error", err) + switch statusCode { case http.StatusNotFound: return runnerErrors.ErrNotFound case http.StatusUnauthorized: @@ -249,7 +254,7 @@ func parseError(response *github.Response, err error) error { case http.StatusUnprocessableEntity: return runnerErrors.ErrBadRequest default: - if response.StatusCode >= 100 && response.StatusCode < 300 { + if statusCode >= 100 && statusCode < 300 { return nil } if err != nil {