From 9d28d9eb47e1ab043880646c7ff9b40c82d681f2 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Thu, 20 Oct 2022 15:53:58 -0400 Subject: [PATCH] cli: prevent panic on `operator debug` (#14992) If the API returns an error during debug bundle collection the CLI was expanding the wrong error object, resulting in a panic since `err` is `nil`. --- .changelog/14992.txt | 3 +++ command/operator_debug.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .changelog/14992.txt diff --git a/.changelog/14992.txt b/.changelog/14992.txt new file mode 100644 index 000000000..86c0d8788 --- /dev/null +++ b/.changelog/14992.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: prevent a panic when the Nomad API returns an error while collecting a debug bundle +``` diff --git a/command/operator_debug.go b/command/operator_debug.go index b1ac4f9ee..09fdcc07d 100644 --- a/command/operator_debug.go +++ b/command/operator_debug.go @@ -1404,7 +1404,7 @@ func writeResponseStreamOrErrorToFile[T any](obj []T, apiErr error, getWriterFn defer writer.Close() if apiErr != nil { - wrapped := errorWrapper{Error: err.Error()} + wrapped := errorWrapper{Error: apiErr.Error()} return writeJSON(wrapped, writer) }