Skip to content

Commit

Permalink
bugfix: correctly populate stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoe committed Mar 1, 2023
1 parent 28b9649 commit 1befeee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tfexec/cmd_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tfexec

import (
"context"
"fmt"
"os/exec"
"strings"
"sync"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tfexec/internal/e2etest/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"os"
"os/exec"
"strings"
"testing"
"time"

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

Expand Down

0 comments on commit 1befeee

Please sign in to comment.