cli: fix panic on job restart (#17346)

When monitoring the replacement allocation, if the
`Allocations().Info()` request fails, the `alloc` variable is `nil`, so
it should not be read.
This commit is contained in:
Luiz Aoqui 2023-05-30 11:08:49 -04:00 committed by GitHub
parent bb2395031b
commit e236d6dedd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

3
.changelog/17346.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
cli: Fix a panic in the `nomad job restart` command when monitoring replacement allocations
```

View File

@ -1045,7 +1045,7 @@ func (c *JobRestartCommand) monitorReplacementAlloc(
alloc, qm, err := c.client.Allocations().Info(currentAllocID, q) alloc, qm, err := c.client.Allocations().Info(currentAllocID, q)
if err != nil { if err != nil {
errCh <- fmt.Errorf("Failed to retrieve allocation %q: %w", limit(alloc.ID, c.length), err) errCh <- fmt.Errorf("Failed to retrieve allocation %q: %w", limit(currentAllocID, c.length), err)
return return
} }