MCPcopy Index your code
hub / github.com/docker/cli / getExitCode

Function getExitCode

cmd/docker/docker.go:99–120  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
99func 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

Callers 4

mainFunction · 0.70
cmdErrorMessageFunction · 0.70
TestUserTerminatedErrorFunction · 0.70
TestGetExitCodeFunction · 0.70

Calls

no outgoing calls

Tested by 2

TestUserTerminatedErrorFunction · 0.56
TestGetExitCodeFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…