Exit with the code of ExitCoder if exists
This commit is contained in:
parent
ce42837702
commit
6c50b15a27
21
errors.go
21
errors.go
@ -85,10 +85,8 @@ func HandleExitCoder(err error) {
|
||||
}
|
||||
|
||||
if multiErr, ok := err.(MultiError); ok {
|
||||
for _, merr := range multiErr.Errors {
|
||||
fmt.Fprintln(ErrWriter, merr)
|
||||
}
|
||||
OsExiter(1)
|
||||
code := handleMultiError(multiErr)
|
||||
OsExiter(code)
|
||||
return
|
||||
}
|
||||
|
||||
@ -97,3 +95,18 @@ func HandleExitCoder(err error) {
|
||||
}
|
||||
OsExiter(1)
|
||||
}
|
||||
|
||||
func handleMultiError(multiErr MultiError) int {
|
||||
code := 1
|
||||
for _, merr := range multiErr.Errors {
|
||||
if multiErr2, ok := merr.(MultiError); ok {
|
||||
code = handleMultiError(multiErr2)
|
||||
} else {
|
||||
fmt.Fprintln(ErrWriter, merr)
|
||||
if exitErr, ok := merr.(ExitCoder); ok {
|
||||
code = exitErr.ExitCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
return code
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user