From 5370d9cb76a8075332f5ab6a0efef9fba28ba19b Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Sat, 15 Jun 2019 06:24:42 -0400 Subject: Add new exit codes to rm & rmi for running containers & dependencies This enables programs and scripts wrapping the podman command to handle 'podman rm' and 'podman rmi' failures caused by paused or running containers or due to images having other child images or dependent containers. These errors are common enough that it makes sense to have a more machine readable way of detecting them than parsing the standard error output. Signed-off-by: Ondrej Zoder Signed-off-by: Daniel J Walsh --- cmd/podman/errors_remote.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'cmd/podman/errors_remote.go') diff --git a/cmd/podman/errors_remote.go b/cmd/podman/errors_remote.go index 1e276be10..19df2d2d8 100644 --- a/cmd/podman/errors_remote.go +++ b/cmd/podman/errors_remote.go @@ -9,6 +9,7 @@ import ( "syscall" "github.com/containers/libpod/cmd/podman/varlink" + "github.com/containers/libpod/libpod/define" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -43,3 +44,22 @@ func outputError(err error) { fmt.Fprintln(os.Stderr, "Error:", ne.Error()) } } + +func setExitCode(err error) int { + cause := errors.Cause(err) + switch e := cause.(type) { + // For some reason golang wont let me list them with commas so listing them all. + case *iopodman.ContainerNotFound: + return 1 + case *iopodman.InvalidState: + return 2 + default: + switch e { + case define.ErrNoSuchCtr: + return 1 + case define.ErrCtrStateInvalid: + return 2 + } + } + return exitCode +} -- cgit v1.2.3-54-g00ecf