Skip to content

Commit

Permalink
fix: exit commands with non zero exit code if plan or apply fails (#1257
Browse files Browse the repository at this point in the history
)

* fix: exit commands with non zero exit code if plan or apply fails

* refactor: refactor

* fix: return non zero if error is nil
  • Loading branch information
suzuki-shunsuke authored May 9, 2024
1 parent 3d98568 commit 6ee25f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pkg/apperr/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ func HandleExit(err error) int {
logE := logrus.NewEntry(logrus.New())

if exitErr, ok := err.(ExitCoder); ok { //nolint:errorlint
if err.Error() != "" {
errMsg := err.Error()
if errMsg != "" {
if _, ok := exitErr.(ErrorFormatter); ok {
logrus.Errorf("%+v", err)
} else {
logerr.WithError(logE, err).Error("tfcmt failed")
}
}
return exitErr.ExitCode()
if code := exitErr.ExitCode(); code != 0 {
return code
}
if errMsg == "" {
return ExitCodeOK
}
return ExitCodeError
}

logerr.WithError(logE, err).Error("tfcmt failed")
Expand Down
2 changes: 1 addition & 1 deletion pkg/apperr/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestHandleError(t *testing.T) {
{
name: "case 1",
err: NewExitError(0, errors.New("error")),
exitCode: 0,
exitCode: 1,
},
{
name: "case 2",
Expand Down

0 comments on commit 6ee25f1

Please sign in to comment.