From a4e6b9a3b183236d76f09cb5d3877c2c8739a5b5 Mon Sep 17 00:00:00 2001 From: Evan Lin Date: Tue, 12 Nov 2019 14:06:21 +1300 Subject: [PATCH] Added ErrAppNotRunning --- pkg/visor/rpc.go | 6 +----- pkg/visor/rpc_test.go | 3 +-- pkg/visor/visor.go | 5 ++++- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/visor/rpc.go b/pkg/visor/rpc.go index c2f51362b3..0a55339645 100644 --- a/pkg/visor/rpc.go +++ b/pkg/visor/rpc.go @@ -190,11 +190,7 @@ func (r *RPC) StartApp(name *string, _ *struct{}) error { // StopApp stops App with provided name. func (r *RPC) StopApp(name *string, _ *struct{}) error { - err := r.node.StopApp(*name) - if err == ErrUnknownApp { - err = errors.New("app is either non-existent, or is already stopped") - } - return err + return r.node.StopApp(*name) } // SetAutoStartIn is input for SetAutoStart. diff --git a/pkg/visor/rpc_test.go b/pkg/visor/rpc_test.go index b64ed85c34..0dc2d3dd27 100644 --- a/pkg/visor/rpc_test.go +++ b/pkg/visor/rpc_test.go @@ -1,7 +1,6 @@ package visor import ( - "errors" "fmt" "net/http" "os" @@ -125,7 +124,7 @@ func TestStartStopApp(t *testing.T) { err = rpc.StopApp(&unknownApp, nil) require.Error(t, err) - assert.Equal(t, errors.New("app is either non-existent, or is already stopped"), err) + assert.Equal(t, ErrAppNotRunning, err) require.NoError(t, rpc.StopApp(&app, nil)) time.Sleep(100 * time.Millisecond) diff --git a/pkg/visor/visor.go b/pkg/visor/visor.go index f2e1979664..7445f90f56 100644 --- a/pkg/visor/visor.go +++ b/pkg/visor/visor.go @@ -50,6 +50,9 @@ const ( // ErrUnknownApp represents lookup error for App related calls. var ErrUnknownApp = errors.New("unknown app") +// ErrAppNotRunning occurs when an app is attempted to be stopped when it was not running. +var ErrAppNotRunning = errors.New("app is not running") + // Version is the node version. const Version = "0.0.1" @@ -532,7 +535,7 @@ func (node *Node) StopApp(appName string) error { node.startedMu.Unlock() if bind == nil { - return ErrUnknownApp + return ErrAppNotRunning } return node.stopApp(appName, bind)