diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2019-09-07 05:40:45 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2019-09-12 16:20:01 -0400 |
commit | 535111b5d5cfa0d203df77e6d6b0b69eda46bb82 (patch) | |
tree | a22a31672391f8d2235fccaa891162a6f9467e7e /libpod/define/exec_codes.go | |
parent | af8fedcc78674d71d43ca3000438c42b7b6b6994 (diff) | |
download | podman-535111b5d5cfa0d203df77e6d6b0b69eda46bb82.tar.gz podman-535111b5d5cfa0d203df77e6d6b0b69eda46bb82.tar.bz2 podman-535111b5d5cfa0d203df77e6d6b0b69eda46bb82.zip |
Use exit code constants
We have leaked the exit number codess all over the code, this patch
removes the numbers to constants.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod/define/exec_codes.go')
-rw-r--r-- | libpod/define/exec_codes.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libpod/define/exec_codes.go b/libpod/define/exec_codes.go index 7184f1e59..33d631326 100644 --- a/libpod/define/exec_codes.go +++ b/libpod/define/exec_codes.go @@ -1,6 +1,8 @@ package define import ( + "strings" + "github.com/pkg/errors" ) @@ -28,3 +30,19 @@ 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()) + if strings.Contains(e, "file not found") || + strings.Contains(e, "no such file or directory") { + return ExecErrorCodeNotFound + } + + return ExecErrorCodeCannotInvoke +} |