From e2eb8f719b3a4de04701a23ed142c7537e4e6d96 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Tue, 26 Mar 2024 16:43:09 +0200 Subject: [PATCH] Check for nil pointer before dereferencing Signed-off-by: Gabriel Adrian Samfira --- cmd/garm-cli/cmd/log.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/garm-cli/cmd/log.go b/cmd/garm-cli/cmd/log.go index 1dab7c1d..ccd55ca6 100644 --- a/cmd/garm-cli/cmd/log.go +++ b/cmd/garm-cli/cmd/log.go @@ -46,10 +46,16 @@ var logCmd = &cobra.Command{ if err != nil { var resp apiParams.APIErrorResponse var msg string - if err := json.NewDecoder(response.Body).Decode(&resp); err == nil { - msg = resp.Details + var status string + if response != nil { + if response.Body != nil { + if err := json.NewDecoder(response.Body).Decode(&resp); err == nil { + msg = resp.Details + } + } + status = response.Status } - log.Fatalf("failed to stream logs: %s (%s)", msg, response.Status) + log.Fatalf("failed to stream logs: %q %s (%s)", err, msg, status) } defer c.Close()