aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2019-11-27 13:04:01 +0100
committerGiuseppe Scrivano <gscrivan@redhat.com>2019-11-28 09:51:58 +0100
commitbc485bce47f55135d6ead80537bc145edb779ae9 (patch)
tree5592104152b89ce178454d29e7a3f70881c5da3e
parent63924775ba221172874df7a1d992a76c25b9af38 (diff)
downloadpodman-bc485bce47f55135d6ead80537bc145edb779ae9.tar.gz
podman-bc485bce47f55135d6ead80537bc145edb779ae9.tar.bz2
podman-bc485bce47f55135d6ead80537bc145edb779ae9.zip
oci: print only matching part for the errors
when parsing the OCI error, be sure to discard any other output that is not matched. The full output is still printed with --log-level=debug. Closes: https://github.com/containers/libpod/issues/4574 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
-rw-r--r--libpod/oci_util.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/libpod/oci_util.go b/libpod/oci_util.go
index c1a7f1c9a..3345220ac 100644
--- a/libpod/oci_util.go
+++ b/libpod/oci_util.go
@@ -83,11 +83,22 @@ func bindPorts(ports []ocicni.PortMapping) ([]*os.File, error) {
func getOCIRuntimeError(runtimeMsg string) error {
r := strings.ToLower(runtimeMsg)
- if match, _ := regexp.MatchString(".*permission denied.*|.*operation not permitted.*", r); match {
- return errors.Wrapf(define.ErrOCIRuntimePermissionDenied, "%s", strings.Trim(runtimeMsg, "\n"))
+
+ includeFullOutput := logrus.GetLevel() == logrus.DebugLevel
+
+ if match := regexp.MustCompile(".*permission denied.*|.*operation not permitted.*").FindString(r); match != "" {
+ errStr := match
+ if includeFullOutput {
+ errStr = runtimeMsg
+ }
+ return errors.Wrapf(define.ErrOCIRuntimePermissionDenied, "%s", strings.Trim(errStr, "\n"))
}
- if match, _ := regexp.MatchString(".*executable file not found in.*|.*no such file or directory.*", r); match {
- return errors.Wrapf(define.ErrOCIRuntimeNotFound, "%s", strings.Trim(runtimeMsg, "\n"))
+ if match := regexp.MustCompile(".*executable file not found in.*|.*no such file or directory.*").FindString(r); match != "" {
+ errStr := match
+ if includeFullOutput {
+ errStr = runtimeMsg
+ }
+ return errors.Wrapf(define.ErrOCIRuntimeNotFound, "%s", strings.Trim(errStr, "\n"))
}
return errors.Wrapf(define.ErrOCIRuntime, "%s", strings.Trim(runtimeMsg, "\n"))
}