From b7bc3aae6f5e1183a4baca0fca2b7fdf42ec152a Mon Sep 17 00:00:00 2001 From: Ivo Verberk Date: Thu, 7 Apr 2016 20:22:09 +0200 Subject: [PATCH] Fixes a panic when fs commands with a job parameter return zero allocations --- command/fs.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/command/fs.go b/command/fs.go index 4b3a47174..f42b60334 100644 --- a/command/fs.go +++ b/command/fs.go @@ -1,6 +1,7 @@ package command import ( + "fmt" "math/rand" "time" @@ -29,6 +30,12 @@ func (f *FSCommand) Run(args []string) int { func getRandomJobAlloc(client *api.Client, jobID string) (string, error) { var runningAllocs []*api.AllocationListStub allocs, _, err := client.Jobs().Allocations(jobID, nil) + + // Check that the job actually has allocations + if len(allocs) == 0 { + return "", fmt.Errorf("job %q doesn't exist or it has no allocations", jobID) + } + for _, v := range allocs { if v.ClientStatus == "running" { runningAllocs = append(runningAllocs, v)