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)
| 97 | // If err is a [cli.StatusError] and has a StatusCode set, it uses the |
| 98 | // status-code from it, otherwise it returns "1" for any error. |
| 99 | func getExitCode(err error) int { |
| 100 | if err == nil { |
| 101 | return 0 |
| 102 | } |
| 103 | |
| 104 | var userTerminatedErr errCtxSignalTerminated |
| 105 | if errors.As(err, &userTerminatedErr) { |
| 106 | s, ok := userTerminatedErr.signal.(syscall.Signal) |
| 107 | if !ok { |
| 108 | return 1 |
| 109 | } |
| 110 | return 128 + int(s) |
| 111 | } |
| 112 | |
| 113 | var stErr cli.StatusError |
| 114 | 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. |
| 115 | return stErr.StatusCode |
| 116 | } |
| 117 | |
| 118 | // No status-code provided; all errors should have a non-zero exit code. |
| 119 | return 1 |
| 120 | } |
| 121 | |
| 122 | // cmdErrorMessage extracts an error message suitable for passing to plugin |
| 123 | // hooks. If the error's message is empty (e.g. a StatusError with only an |
no outgoing calls
searching dependent graphs…