MCPcopy
hub / github.com/urfave/cli / HandleExitCoder

Function HandleExitCoder

errors.go:147–169  ·  errors.go::HandleExitCoder

HandleExitCoder handles errors implementing ExitCoder by printing their message and calling OsExiter with the given exit code. If the given error instead implements MultiError, each error will be checked for the ExitCoder interface, and OsExiter will be called with the last exit code found, or exit

(err error)

Source from the content-addressed store, hash-verified

145//
146// This function is the default error-handling behavior for a Command.
147func HandleExitCoder(err error) {
148 if err == nil {
149 return
150 }
151
152 if exitErr, ok := err.(ExitCoder); ok {
153 if msg := err.Error(); msg != "" {
154 if _, ok := exitErr.(ErrorFormatter); ok {
155 _, _ = fmt.Fprintf(ErrWriter, "%+v\n", err)
156 } else {
157 _, _ = fmt.Fprintln(ErrWriter, err)
158 }
159 }
160 OsExiter(exitErr.ExitCode())
161 return
162 }
163
164 if multiErr, ok := err.(MultiError); ok {
165 code := handleMultiError(multiErr)
166 OsExiter(code)
167 return
168 }
169}
170
171func handleMultiError(multiErr MultiError) int {
172 code := 1

Calls 3

handleMultiErrorFunction · 0.85
ExitCodeMethod · 0.65
ErrorMethod · 0.45