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

Function toStatusError

cli/command/container/run.go:330–356  ·  view source on GitHub ↗

toStatusError attempts to detect specific error-conditions to assign an appropriate exit-code for situations where the problem originates from the container. It returns [cli.StatusError] with the original error message and the Status field set as follows: - 125: for generic failures sent back from

(err error)

Source from the content-addressed store, hash-verified

328// - 126: if container start fails with 'permission denied' error
329// - 127: if container start fails with 'not found'/'no such' error
330func toStatusError(err error) error {
331 // TODO(thaJeztah): some of these errors originate from the container: should we actually suggest "--help" for those?
332
333 errMsg := err.Error()
334
335 if strings.Contains(errMsg, "executable file not found") || strings.Contains(errMsg, "no such file or directory") || strings.Contains(errMsg, "system cannot find the file specified") {
336 return cli.StatusError{
337 Cause: err,
338 Status: withHelp(err, "run").Error(),
339 StatusCode: 127,
340 }
341 }
342
343 if strings.Contains(errMsg, syscall.EACCES.Error()) || strings.Contains(errMsg, syscall.EISDIR.Error()) {
344 return cli.StatusError{
345 Cause: err,
346 Status: withHelp(err, "run").Error(),
347 StatusCode: 126,
348 }
349 }
350
351 return cli.StatusError{
352 Cause: err,
353 Status: withHelp(err, "run").Error(),
354 StatusCode: 125,
355 }
356}

Callers 1

runContainerFunction · 0.85

Calls 3

withHelpFunction · 0.85
ContainsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…