diff options
Diffstat (limited to 'libpod/define/exec_codes.go')
-rw-r--r-- | libpod/define/exec_codes.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libpod/define/exec_codes.go b/libpod/define/exec_codes.go index 7184f1e59..f94616b33 100644 --- a/libpod/define/exec_codes.go +++ b/libpod/define/exec_codes.go @@ -1,7 +1,10 @@ package define import ( + "strings" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) const ( @@ -28,3 +31,20 @@ func TranslateExecErrorToExitCode(originalEC int, err error) int { } return originalEC } + +// ExitCode reads the error message when failing to executing container process +// and then returns 0 if no error, ExecErrorCodeNotFound if command does not exist, or ExecErrorCodeCannotInvoke for +// all other errors +func ExitCode(err error) int { + if err == nil { + return 0 + } + e := strings.ToLower(err.Error()) + logrus.Debugf("ExitCode msg: %q", e) + if strings.Contains(e, "not found") || + strings.Contains(e, "no such file") { + return ExecErrorCodeNotFound + } + + return ExecErrorCodeCannotInvoke +} |