diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-12-17 13:16:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-17 13:16:23 +0100 |
commit | 820cf0e0661764de4e61e3d27a603acec817a363 (patch) | |
tree | 590b0a9811d1bc923385ab4ad4309b067af69ba4 /cmd/podman/utils/error.go | |
parent | c9a3f4ec44c4507c0a801635b93d840723826b7a (diff) | |
parent | 6423174c67d486522354806bf326c843c07d18c1 (diff) | |
download | podman-820cf0e0661764de4e61e3d27a603acec817a363.tar.gz podman-820cf0e0661764de4e61e3d27a603acec817a363.tar.bz2 podman-820cf0e0661764de4e61e3d27a603acec817a363.zip |
Merge pull request #12622 from flouthoc/return_exit_code_for_build
build: relay `exitcode` from imagebuildah to registry
Diffstat (limited to 'cmd/podman/utils/error.go')
-rw-r--r-- | cmd/podman/utils/error.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/podman/utils/error.go b/cmd/podman/utils/error.go index 2d58bc70d..aab1da675 100644 --- a/cmd/podman/utils/error.go +++ b/cmd/podman/utils/error.go @@ -1,8 +1,13 @@ package utils import ( + "errors" "fmt" "os" + "strconv" + "strings" + + buildahCLI "github.com/containers/buildah/pkg/cli" ) type OutputErrors []error @@ -17,3 +22,24 @@ func (o OutputErrors) PrintErrors() (lastError error) { } return } + +/* For remote client, server does not returns error with exit code + instead returns a message and we cast it to a new error. + + Following function performs parsing on build error and returns + exit status which was exepected for this current build +*/ +func ExitCodeFromBuildError(errorMsg string) (int, error) { + if strings.Contains(errorMsg, "exit status") { + errorSplit := strings.Split(errorMsg, " ") + if errorSplit[len(errorSplit)-2] == "status" { + tmpSplit := strings.Split(errorSplit[len(errorSplit)-1], "\n") + exitCodeRemote, err := strconv.Atoi(tmpSplit[0]) + if err == nil { + return exitCodeRemote, nil + } + return buildahCLI.ExecErrorCodeGeneric, err + } + } + return buildahCLI.ExecErrorCodeGeneric, errors.New("error message does not contains a valid exit code") +} |