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.
Этот коммит содержится в:
родитель
e3aa13c2a6
коммит
c60c36f0a8
2 изменённых файлов: 3 добавлений и 14 удалений
|
@ -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)
|
||||
}
|
||||
|
|
11
main.go
11
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)
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче