diff --git a/libmachine/host/host.go b/libmachine/host/host.go index a5ccd53043..c43800502c 100644 --- a/libmachine/host/host.go +++ b/libmachine/host/host.go @@ -2,14 +2,13 @@ package host import ( "errors" - "fmt" "regexp" - "strings" "github.com/docker/machine/libmachine/auth" "github.com/docker/machine/libmachine/drivers" "github.com/docker/machine/libmachine/engine" "github.com/docker/machine/libmachine/log" + "github.com/docker/machine/libmachine/mcnerror" "github.com/docker/machine/libmachine/mcnutils" "github.com/docker/machine/libmachine/provision" "github.com/docker/machine/libmachine/provision/pkgaction" @@ -94,7 +93,10 @@ func (creator *StandardSSHClientCreator) CreateSSHClient(d drivers.Driver) (ssh. func (h *Host) runActionForState(action func() error, desiredState state.State) error { if drivers.MachineInState(h.Driver, desiredState)() { - return fmt.Errorf("Machine %q is already %s.", h.Name, strings.ToLower(desiredState.String())) + return mcnerror.ErrHostAlreadyInState{ + Name: h.Name, + State: desiredState, + } } if err := action(); err != nil { diff --git a/libmachine/mcnerror/errors.go b/libmachine/mcnerror/errors.go index af072cd503..4a409cee75 100644 --- a/libmachine/mcnerror/errors.go +++ b/libmachine/mcnerror/errors.go @@ -3,6 +3,9 @@ package mcnerror import ( "errors" "fmt" + "strings" + + "github.com/docker/machine/libmachine/state" ) var ( @@ -32,3 +35,12 @@ type ErrDuringPreCreate struct { func (e ErrDuringPreCreate) Error() string { return fmt.Sprintf("Error with pre-create check: %q", e.Cause) } + +type ErrHostAlreadyInState struct { + Name string + State state.State +} + +func (e ErrHostAlreadyInState) Error() string { + return fmt.Sprintf("Machine %q is already %s.", e.Name, strings.ToLower(e.State.String())) +}