MCPcopy Create free account
hub / github.com/docker/cli / getExitCode

Function getExitCode

cmd/docker-trust/main.go:93–114  ·  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

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.
93func 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}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…