Skip to content

Commit

Permalink
Fix #34. (#35)
Browse files Browse the repository at this point in the history
- Fix a case where panic occurs, if 'terraform init' does not exit
cleanly.
- Check the exit status via a type assertion to exec.ExitError.
- If the aforementioned type assertion fails, the panic still occurs.
  • Loading branch information
jlucktay authored Aug 30, 2019
1 parent 58304da commit 1763b85
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/stack/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/exec"
"strings"
"sync"
"syscall"

"github.com/jlucktay/stack/pkg/common"
"github.com/spf13/viper"
Expand Down Expand Up @@ -141,7 +142,13 @@ func initStack() {
go func() {
errWait := cmdInit.Wait()
if errWait != nil {
panic(errWait)
if exitErr, ok := errWait.(*exec.ExitError); ok {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
log.Printf("Exit status: %d", status.ExitStatus())
}
} else {
panic(errWait)
}
}
wg.Wait()
close(chOut)
Expand Down

0 comments on commit 1763b85

Please sign in to comment.