Skip to content

Commit

Permalink
Merge pull request #6828 from hashicorp/b/nomad-monitor-panic
Browse files Browse the repository at this point in the history
command: error when no node is found for `monitor`
  • Loading branch information
endocrimes committed Dec 10, 2019
2 parents bbb6b2a + c91f8da commit 34a5a3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions command/agent_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (c *MonitorCommand) Run(args []string) int {
return 1
}

if len(nodes) == 0 {
c.Ui.Error(fmt.Sprintf("No node(s) with prefix or id %q found", nodeID))
return 1
}

if len(nodes) > 1 {
out := formatNodeStubList(nodes, false)
c.Ui.Output(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", out))
Expand Down
11 changes: 10 additions & 1 deletion command/agent_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestMonitorCommand_Implements(t *testing.T) {

func TestMonitorCommand_Fails(t *testing.T) {
t.Parallel()
srv, _, _ := testServer(t, false, nil)
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
Expand All @@ -33,4 +33,13 @@ func TestMonitorCommand_Fails(t *testing.T) {
if code := cmd.Run([]string{"-address=nope"}); code != 1 {
t.Fatalf("exepected exit code 1, got: %d", code)
}

// Fails on nonexistent node
if code := cmd.Run([]string{"-address=" + url, "-node-id=12345678-abcd-efab-cdef-123456789abc"}); code != 1 {
t.Fatalf("expected exit 1, got: %d", code)
}
if out := ui.ErrorWriter.String(); !strings.Contains(out, "No node(s) with prefix") {
t.Fatalf("expected not found error, got: %s", out)
}
ui.ErrorWriter.Reset()
}

0 comments on commit 34a5a3a

Please sign in to comment.