diff --git a/tfexec/cmd_default.go b/tfexec/cmd_default.go index 7323d555..79dacc93 100644 --- a/tfexec/cmd_default.go +++ b/tfexec/cmd_default.go @@ -5,6 +5,7 @@ package tfexec import ( "context" + "fmt" "os/exec" "strings" "sync" @@ -76,15 +77,15 @@ func (tf *Terraform) runTerraformCmd(ctx context.Context, cmd *exec.Cmd) error { } } if err != nil { - return err + return fmt.Errorf("%w\n%s", err, errBuf.String()) } // Return error if there was an issue reading the std out/err if errStdout != nil && ctx.Err() != nil { - return errStdout + return fmt.Errorf("%w\n%s", errStdout, errBuf.String()) } if errStderr != nil && ctx.Err() != nil { - return errStderr + return fmt.Errorf("%w\n%s", errStderr, errBuf.String()) } return nil diff --git a/tfexec/cmd_linux.go b/tfexec/cmd_linux.go index 9975791a..440fafe8 100644 --- a/tfexec/cmd_linux.go +++ b/tfexec/cmd_linux.go @@ -2,6 +2,7 @@ package tfexec import ( "context" + "fmt" "os/exec" "strings" "sync" @@ -81,15 +82,15 @@ func (tf *Terraform) runTerraformCmd(ctx context.Context, cmd *exec.Cmd) error { } } if err != nil { - return err + return fmt.Errorf("%w\n%s", err, errBuf.String()) } // Return error if there was an issue reading the std out/err if errStdout != nil && ctx.Err() != nil { - return errStdout + return fmt.Errorf("%w\n%s", errStdout, errBuf.String()) } if errStderr != nil && ctx.Err() != nil { - return errStderr + return fmt.Errorf("%w\n%s", errStderr, errBuf.String()) } return nil diff --git a/tfexec/internal/e2etest/errors_test.go b/tfexec/internal/e2etest/errors_test.go index d75986da..6ce838fa 100644 --- a/tfexec/internal/e2etest/errors_test.go +++ b/tfexec/internal/e2etest/errors_test.go @@ -9,6 +9,7 @@ import ( "errors" "os" "os/exec" + "strings" "testing" "time" @@ -108,6 +109,10 @@ func TestLockedState(t *testing.T) { if err == nil { t.Fatal("expected error, but didn't find one") } + + if !strings.Contains(err.Error(), "state lock") { + t.Fatal("expected err.Error() to contain 'state lock', but it did not") + } }) }