From 9b32fb1d17ae077f3a393c383e0f3524b047336a Mon Sep 17 00:00:00 2001 From: Hannes Gustafsson Date: Thu, 24 Oct 2024 14:44:45 +0100 Subject: [PATCH] SD-838: fix panic (#33) * Fix potential panic The change [1] introduced a potential panic as it is trying to log the app name when a failure happens, but the app variable is overridden during such a failure and is thus nil. This results in the following panic. panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x20ddccb] goroutine 367 [running]: internal/pkg/argocd.generateDiffOfAComponent() internal/pkg/argocd/argocd.go:477 internal/pkg/argocd.GenerateDiffOfChangedComponents() internal/pkg/argocd/argocd.go:561 internal/pkg/githubapi.HandlePREvent() internal/pkg/githubapi/github.go:161 internal/pkg/githubapi.handleEvent() internal/pkg/githubapi/github.go:382 created by internal/pkg/githubapi.ReciveWebhook internal/pkg/githubapi/github.go:322 By instead using the name from the query constructed prior, the panic should be avoided. [1] adbd91328b2edce48ee4607f101ecb2b6528d77b --- internal/pkg/argocd/argocd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/argocd/argocd.go b/internal/pkg/argocd/argocd.go index e1dbf96a..ae63f207 100644 --- a/internal/pkg/argocd/argocd.go +++ b/internal/pkg/argocd/argocd.go @@ -474,7 +474,7 @@ func generateDiffOfAComponent(ctx context.Context, commentDiff bool, componentPa app, err := ac.app.Get(ctx, &appNameQuery) if err != nil { componentDiffResult.DiffError = err - log.Errorf("Error getting app(HardRefresh) %s: %v", app.Name, err) + log.Errorf("Error getting app(HardRefresh) %v: %v", appNameQuery.Name, err) return componentDiffResult } log.Debugf("Got ArgoCD app %s", app.Name)