From 507fbcb1fb49617d12f4708eb4fcf90d2eb21204 Mon Sep 17 00:00:00 2001 From: Michael Dresser Date: Wed, 13 Jul 2022 13:00:09 -0400 Subject: [PATCH] Check query error before accessing response We had a bug where failed queries in the TUI would return an error or an empty response but we were trying to access the response before checking the error or the response size. This shifts logic around to handle the error first and then check if the response is empty before trying to access it. --- pkg/cmd/tui.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/tui.go b/pkg/cmd/tui.go index 9c84667..2dfbb89 100644 --- a/pkg/cmd/tui.go +++ b/pkg/cmd/tui.go @@ -242,14 +242,16 @@ func runTUI(ko *KubeOptions, do displayOptions, qo query.QueryBackendOptions) er QueryBackendOptions: qo, }) - allocations = allocs[0] - if err != nil && strings.Contains(err.Error(), "context canceled") { // do nothing, because the context got canceled to favor a more // recent window request from the user } else if err != nil { log.Errorf("failed to query agg cost model: %s", err) + } else if len(allocations) == 0 { + log.Errorf("Allocation response was empty. Not updating the table.") } else { + allocations = allocs[0] + lastUpdated = time.Now() app.QueueUpdateDraw(func() { redrawTable()