Skip to content

Commit

Permalink
Added ErrAppNotRunning
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Lin committed Nov 12, 2019
1 parent 78032f5 commit a4e6b9a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 1 addition & 5 deletions pkg/visor/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions pkg/visor/rpc_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package visor

import (
"errors"
"fmt"
"net/http"
"os"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/visor/visor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a4e6b9a

Please sign in to comment.