getExitCode returns the exit-code to use for the given error. If err is a [cli.StatusError] and has a StatusCode set, it uses the status-code from it, otherwise it returns "1" for any error.
(err error)
| 91 | // If err is a [cli.StatusError] and has a StatusCode set, it uses the |
| 92 | // status-code from it, otherwise it returns "1" for any error. |
| 93 | func getExitCode(err error) int { |
| 94 | if err == nil { |
| 95 | return 0 |
| 96 | } |
| 97 | |
| 98 | var userTerminatedErr errCtxSignalTerminated |
| 99 | if errors.As(err, &userTerminatedErr) { |
| 100 | s, ok := userTerminatedErr.signal.(syscall.Signal) |
| 101 | if !ok { |
| 102 | return 1 |
| 103 | } |
| 104 | return 128 + int(s) |
| 105 | } |
| 106 | |
| 107 | var stErr cli.StatusError |
| 108 | if errors.As(err, &stErr) && stErr.StatusCode != 0 { // FIXME(thaJeztah): StatusCode should never be used with a zero status-code. Check if we do this anywhere. |
| 109 | return stErr.StatusCode |
| 110 | } |
| 111 | |
| 112 | // No status-code provided; all errors should have a non-zero exit code. |
| 113 | return 1 |
| 114 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…