diff --git a/cli/command/stack/ps.go b/cli/command/stack/ps.go index 25bd1eee10..d586b1e1e4 100644 --- a/cli/command/stack/ps.go +++ b/cli/command/stack/ps.go @@ -57,8 +57,7 @@ func runPS(dockerCli command.Cli, options psOptions) error { } if len(tasks) == 0 { - fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", namespace) - return nil + return fmt.Errorf("nothing found in stack: %s", namespace) } format := options.format diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index 282e5e01da..3bb22609b5 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -60,9 +60,9 @@ func TestStackPsEmptyStack(t *testing.T) { cmd := newPsCommand(fakeCli) cmd.SetArgs([]string{"foo"}) - assert.NoError(t, cmd.Execute()) + assert.Error(t, cmd.Execute()) + assert.EqualError(t, cmd.Execute(), "nothing found in stack: foo") assert.Equal(t, "", fakeCli.OutBuffer().String()) - assert.Equal(t, "Nothing found in stack: foo\n", fakeCli.ErrBuffer().String()) } func TestStackPsWithQuietOption(t *testing.T) {