diff options
author | Peter Hunt <pehunt@redhat.com> | 2019-07-23 15:30:05 -0400 |
---|---|---|
committer | Peter Hunt <pehunt@redhat.com> | 2019-07-23 16:49:04 -0400 |
commit | 01a8483a59eed8bc706b5219b903704544b66c10 (patch) | |
tree | a4d389c4964cba790ea3b483a3d0265bb53778d1 /libpod/define | |
parent | 82dce36fb6ef3839c029b7450a75c85cf28cf377 (diff) | |
download | podman-01a8483a59eed8bc706b5219b903704544b66c10.tar.gz podman-01a8483a59eed8bc706b5219b903704544b66c10.tar.bz2 podman-01a8483a59eed8bc706b5219b903704544b66c10.zip |
refactor to reduce duplicated error parsing
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'libpod/define')
-rw-r--r-- | libpod/define/exec_codes.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libpod/define/exec_codes.go b/libpod/define/exec_codes.go index 90a68cf93..7184f1e59 100644 --- a/libpod/define/exec_codes.go +++ b/libpod/define/exec_codes.go @@ -1,5 +1,9 @@ package define +import ( + "github.com/pkg/errors" +) + const ( // ExecErrorCodeGeneric is the default error code to return from an exec session if libpod failed // prior to calling the runtime @@ -11,3 +15,16 @@ const ( // ExecErrorCodeNotFound is the error code to return when a command cannot be found ExecErrorCodeNotFound = 127 ) + +// TranslateExecErrorToExitCode takes an error and checks whether it +// has a predefined exit code associated. If so, it returns that, otherwise it returns +// the exit code originally stated in libpod.Exec() +func TranslateExecErrorToExitCode(originalEC int, err error) int { + if errors.Cause(err) == ErrOCIRuntimePermissionDenied { + return ExecErrorCodeCannotInvoke + } + if errors.Cause(err) == ErrOCIRuntimeNotFound { + return ExecErrorCodeNotFound + } + return originalEC +} |