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)
| 328 | // - 126: if container start fails with 'permission denied' error |
| 329 | // - 127: if container start fails with 'not found'/'no such' error |
| 330 | func 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 | } |
no test coverage detected
searching dependent graphs…