Skip to content

Commit c60c36f

Browse files
aykevldeadprogram
authored andcommitted
all: use ExitCode() call to get exit code of exited process
This is an addition that landed in Go 1.12 but we couldn't use before because we were supporting Go back until Go 1.11. It simplifies the code around processes a bit.
1 parent e3aa13c commit c60c36f

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

loader/loader.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"path/filepath"
1717
"strconv"
1818
"strings"
19-
"syscall"
2019

2120
"github.com/tinygo-org/tinygo/cgo"
2221
"github.com/tinygo-org/tinygo/compileopts"
@@ -110,10 +109,7 @@ func Load(config *compileopts.Config, inputPkgs []string, clangHeaders string, t
110109
err = cmd.Run()
111110
if err != nil {
112111
if exitErr, ok := err.(*exec.ExitError); ok {
113-
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
114-
os.Exit(status.ExitStatus())
115-
}
116-
os.Exit(1)
112+
os.Exit(exitErr.ExitCode())
117113
}
118114
return nil, fmt.Errorf("failed to run `go list`: %s", err)
119115
}

main.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"runtime"
1717
"strings"
1818
"sync/atomic"
19-
"syscall"
2019
"time"
2120

2221
"github.com/mattn/go-colorable"
@@ -166,10 +165,7 @@ func Test(pkgName string, options *compileopts.Options, testCompileOnly bool, ou
166165
if err != nil {
167166
// Propagate the exit code
168167
if err, ok := err.(*exec.ExitError); ok {
169-
if status, ok := err.Sys().(syscall.WaitStatus); ok {
170-
os.Exit(status.ExitStatus())
171-
}
172-
os.Exit(1)
168+
os.Exit(err.ExitCode())
173169
}
174170
return &commandError{"failed to run compiled binary", result.Binary, err}
175171
}
@@ -1080,10 +1076,7 @@ func main() {
10801076
err = cmd.Run()
10811077
if err != nil {
10821078
if exitErr, ok := err.(*exec.ExitError); ok {
1083-
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
1084-
os.Exit(status.ExitStatus())
1085-
}
1086-
os.Exit(1)
1079+
os.Exit(exitErr.ExitCode())
10871080
}
10881081
fmt.Fprintln(os.Stderr, "failed to run `go list`:", err)
10891082
os.Exit(1)

0 commit comments

Comments
 (0)