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`.
This commit is contained in:
Luiz Aoqui 2022-10-20 15:53:58 -04:00 committed by GitHub
parent 08fde3a4ff
commit 593e48e826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

3
.changelog/14992.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
cli: prevent a panic when the Nomad API returns an error while collecting a debug bundle
```

View File

@ -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)
}