have remote.ExitError format errors and status
Since all use cases of ExitStatus are just putting it into fmt.Errorf, usually with the command string, have ExitStatus do that for the caller.
This commit is contained in:
parent
3fbdee0777
commit
ad8642e2c2
|
@ -697,9 +697,6 @@ func (p *provisioner) runCommand(o terraform.UIOutput, comm communicator.Communi
|
|||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if rc, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("Command %q exited with non-zero exit status: %d", cmd.Command, rc)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -756,9 +756,6 @@ func (p *provisioner) runCommand(o terraform.UIOutput, comm communicator.Communi
|
|||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if rc, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("Command %q exited with non-zero exit status: %d", cmd.Command, rc)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -198,10 +198,7 @@ func runScripts(
|
|||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if rc, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("Script exited with non-zero exit status: %d", rc)
|
||||
}
|
||||
return fmt.Errorf("Remote command exited with error: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Upload a blank follow up file in the same path to prevent residual
|
||||
|
|
|
@ -161,9 +161,6 @@ func applyFn(ctx context.Context) error {
|
|||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if rc, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("Curl exited with non-zero exit status: %d", rc)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -186,9 +183,6 @@ func applyFn(ctx context.Context) error {
|
|||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if rc, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("install_salt.sh exited with non-zero exit status: %d", rc)
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -273,9 +267,6 @@ func applyFn(ctx context.Context) error {
|
|||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if rc, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("Script exited with non-zero exit status: %d", rc)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -340,9 +331,6 @@ func (p *provisioner) moveFile(o terraform.UIOutput, comm communicator.Communica
|
|||
return fmt.Errorf("Unable to move %s to %s: %s", src, dst, err)
|
||||
}
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if rc, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("Unable to move %s to %s: exit status: %d", src, dst, rc)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -358,9 +346,6 @@ func (p *provisioner) createDir(o terraform.UIOutput, comm communicator.Communic
|
|||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if _, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("Non-zero exit status.")
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -375,9 +360,6 @@ func (p *provisioner) removeDir(o terraform.UIOutput, comm communicator.Communic
|
|||
return err
|
||||
}
|
||||
if err := cmd.Wait(); err != nil {
|
||||
if _, ok := err.(remote.ExitError); ok {
|
||||
return fmt.Errorf("Non-zero exit status.")
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -69,19 +69,28 @@ func (c *Cmd) Wait() error {
|
|||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return c.err
|
||||
}
|
||||
|
||||
if c.exitStatus != 0 {
|
||||
return ExitError(c.exitStatus)
|
||||
if c.err != nil || c.exitStatus != 0 {
|
||||
return &ExitError{
|
||||
Command: c.Command,
|
||||
ExitStatus: c.exitStatus,
|
||||
Err: c.err,
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type ExitError int
|
||||
|
||||
func (e ExitError) Error() string {
|
||||
return fmt.Sprintf("exit status: %d", e)
|
||||
// ExitError is returned by Wait to indicate and error executing the remote
|
||||
// command, or a non-zero exit status.
|
||||
type ExitError struct {
|
||||
Command string
|
||||
ExitStatus int
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *ExitError) Error() string {
|
||||
if e.Err != nil {
|
||||
return fmt.Sprintf("error executing %q: %v", e.Command, e.Err)
|
||||
}
|
||||
return fmt.Sprintf("%q exit status: %d", e.Command, e.ExitStatus)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue