summaryrefslogtreecommitdiff
path: root/cmd/podman/utils
diff options
context:
space:
mode:
authorAditya Rajan <arajan@redhat.com>2021-12-16 17:07:16 +0530
committerAditya Rajan <arajan@redhat.com>2021-12-17 15:07:50 +0530
commitf566d8b8e5351393c03bc0ff475a18174e57af3f (patch)
tree9235af4b6f3d16bc166202a34100d71b9750e407 /cmd/podman/utils
parentd984fec351c06a95f8a51c7e6ced819c6b17245f (diff)
downloadpodman-f566d8b8e5351393c03bc0ff475a18174e57af3f.tar.gz
podman-f566d8b8e5351393c03bc0ff475a18174e57af3f.tar.bz2
podman-f566d8b8e5351393c03bc0ff475a18174e57af3f.zip
build: relay exitcode from imagebuildah to registry
Podman does not relay exit code from buildah instead returns a generic error code `125`. Following PR allows `podman` to relay exit code from `imagebuildah` to `registry` as it is. Signed-off-by: Aditya Rajan <arajan@redhat.com>
Diffstat (limited to 'cmd/podman/utils')
-rw-r--r--cmd/podman/utils/error.go26
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")
+}