From c60c36f0a8bbfd62fc61a583d4d2c7a8bf64bd58 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 4 Mar 2021 21:52:55 +0100 Subject: [PATCH] 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. --- loader/loader.go | 6 +----- main.go | 11 ++--------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/loader/loader.go b/loader/loader.go index 28f969e5c..423470135 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -16,7 +16,6 @@ import ( "path/filepath" "strconv" "strings" - "syscall" "github.com/tinygo-org/tinygo/cgo" "github.com/tinygo-org/tinygo/compileopts" @@ -110,10 +109,7 @@ func Load(config *compileopts.Config, inputPkgs []string, clangHeaders string, t err = cmd.Run() if err != nil { if exitErr, ok := err.(*exec.ExitError); ok { - if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { - os.Exit(status.ExitStatus()) - } - os.Exit(1) + os.Exit(exitErr.ExitCode()) } return nil, fmt.Errorf("failed to run `go list`: %s", err) } diff --git a/main.go b/main.go index 2e22920ee..dbcbc4d83 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,6 @@ import ( "runtime" "strings" "sync/atomic" - "syscall" "time" "github.com/mattn/go-colorable" @@ -166,10 +165,7 @@ func Test(pkgName string, options *compileopts.Options, testCompileOnly bool, ou if err != nil { // Propagate the exit code if err, ok := err.(*exec.ExitError); ok { - if status, ok := err.Sys().(syscall.WaitStatus); ok { - os.Exit(status.ExitStatus()) - } - os.Exit(1) + os.Exit(err.ExitCode()) } return &commandError{"failed to run compiled binary", result.Binary, err} } @@ -1080,10 +1076,7 @@ func main() { err = cmd.Run() if err != nil { if exitErr, ok := err.(*exec.ExitError); ok { - if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { - os.Exit(status.ExitStatus()) - } - os.Exit(1) + os.Exit(exitErr.ExitCode()) } fmt.Fprintln(os.Stderr, "failed to run `go list`:", err) os.Exit(1)