Files
act_runner/vendor/github.com/docker/docker/pkg/system/exitcode.go
Casey Lee 320e9b6057 fail on error (#20)
ci-via-github-actions
2019-01-23 11:51:22 -08:00

20 lines
503 B
Go

package system // import "github.com/docker/docker/pkg/system"
import (
"fmt"
"os/exec"
"syscall"
)
// GetExitCode returns the ExitStatus of the specified error if its type is
// exec.ExitError, returns 0 and an error otherwise.
func GetExitCode(err error) (int, error) {
exitCode := 0
if exiterr, ok := err.(*exec.ExitError); ok {
if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok {
return procExit.ExitStatus(), nil
}
}
return exitCode, fmt.Errorf("failed to get exit code")
}