From 8abc0a92b680c98b21f1f5d8dcb29e8fa2ffc2ed Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 10 Mar 2016 13:55:45 -0800 Subject: [PATCH] Improved the error related to fs commands --- command/fs_cat.go | 7 +++++++ command/fs_ls.go | 7 +++++++ command/fs_stat.go | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/command/fs_cat.go b/command/fs_cat.go index 974e2d5e3..9a7616ab0 100644 --- a/command/fs_cat.go +++ b/command/fs_cat.go @@ -114,6 +114,13 @@ func (f *FSCatCommand) Run(args []string) int { } } + if alloc.DesiredStatus == "failed" { + allocID := limit(alloc.ID, length) + msg := fmt.Sprintf(`The allocation %q failed to be placed. To see the cause, run: +nomad alloc-status %s`, allocID, allocID) + f.Ui.Error(msg) + return 0 + } // Stat the file to find it's size file, _, err := client.AllocFS().Stat(alloc, path, nil) if err != nil { diff --git a/command/fs_ls.go b/command/fs_ls.go index 65766bff1..9329f1dd2 100644 --- a/command/fs_ls.go +++ b/command/fs_ls.go @@ -120,6 +120,13 @@ func (f *FSListCommand) Run(args []string) int { } } + if alloc.DesiredStatus == "failed" { + allocID := limit(alloc.ID, length) + msg := fmt.Sprintf(`The allocation %q failed to be placed. To see the cause, run: +nomad alloc-status %s`, allocID, allocID) + f.Ui.Error(msg) + return 0 + } // Get the file at the given path files, _, err := client.AllocFS().List(alloc, path, nil) if err != nil { diff --git a/command/fs_stat.go b/command/fs_stat.go index 581f27246..9c163f803 100644 --- a/command/fs_stat.go +++ b/command/fs_stat.go @@ -119,6 +119,13 @@ func (f *FSStatCommand) Run(args []string) int { } } + if alloc.DesiredStatus == "failed" { + allocID := limit(alloc.ID, length) + msg := fmt.Sprintf(`The allocation %q failed to be placed. To see the cause, run: +nomad alloc-status %s`, allocID, allocID) + f.Ui.Error(msg) + return 0 + } // Get the file information file, _, err := client.AllocFS().Stat(alloc, path, nil) if err != nil {