Skip to content

Commit 9c031b9

Browse files
author
Mate Herber
authored
Improve exit code error checking utilizing go error unwrap functionality (#157)
1 parent ee1ed1f commit 9c031b9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

errorutil/errorutil.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
package errorutil
33

44
import (
5+
"errors"
56
"os/exec"
67
"regexp"
78
)
89

910
func exitCode(err error) int {
10-
if exitError, ok := err.(*exec.ExitError); ok {
11+
var exitError *exec.ExitError
12+
if errors.As(err, &exitError) {
1113
return exitError.ProcessState.ExitCode()
1214
}
1315
return -1
@@ -22,7 +24,7 @@ func IsExitStatusError(err error) bool {
2224
func IsExitStatusErrorStr(errString string) bool {
2325
// https://golang.org/src/os/exec_posix.go?s=2421:2459#L87
2426
// example exit status error string: exit status 1
25-
var rex = regexp.MustCompile(`^exit status [0-9]{1,3}$`)
27+
var rex = regexp.MustCompile(`^exit status \d{1,3}$`)
2628
return rex.MatchString(errString)
2729
}
2830

0 commit comments

Comments
 (0)