Handle exec.ExitError
Instead of printing a useless "Failed: exit status 1" message, just exit with the same status as the forked process
@@ -19,6 +19,7 @@ package util
import (
"fmt"
"os"
+ "os/exec"
)
// CheckErr ensures the supplied error is reported and handled correctly. Errors may be reported and/or may cause the process to exit.
@@ -27,6 +28,11 @@ func CheckErr(err error) {
return
}
+ // Handle forked process errors by propagating the exit status
+ if eerr, ok := err.(*exec.ExitError); ok && !eerr.Success() {
+ os.Exit(eerr.ExitCode())
+ }
+
// This error handling leaves a lot to be desired...
_, _ = fmt.Fprintf(os.Stderr, "Failed: %s\n", err.Error())
os.Exit(1)
