summaryrefslogtreecommitdiff
path: root/pkg/errorhandling/errorhandling.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-05-05 17:25:04 +0200
committerGitHub <noreply@github.com>2020-05-05 17:25:04 +0200
commite6235ef8f1a3111f8f1afbb1bf64f0e6da704a5b (patch)
tree0e9adb10b78b589120b81b49c46b41cc75da7966 /pkg/errorhandling/errorhandling.go
parent4a1331d0afd9a21ff9465916d4006ff7297ae07c (diff)
parent7f97896c59d23d9dda704b19203a9ceb49b57237 (diff)
downloadpodman-e6235ef8f1a3111f8f1afbb1bf64f0e6da704a5b.tar.gz
podman-e6235ef8f1a3111f8f1afbb1bf64f0e6da704a5b.tar.bz2
podman-e6235ef8f1a3111f8f1afbb1bf64f0e6da704a5b.zip
Merge pull request #6076 from vrothberg/rmi-v2.2
image removal: refactor part 2
Diffstat (limited to 'pkg/errorhandling/errorhandling.go')
-rw-r--r--pkg/errorhandling/errorhandling.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/pkg/errorhandling/errorhandling.go b/pkg/errorhandling/errorhandling.go
index 970d47636..3117b0ca4 100644
--- a/pkg/errorhandling/errorhandling.go
+++ b/pkg/errorhandling/errorhandling.go
@@ -2,10 +2,46 @@ package errorhandling
import (
"os"
+ "strings"
+ "github.com/hashicorp/go-multierror"
+ "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
+// JoinErrors converts the error slice into a single human-readable error.
+func JoinErrors(errs []error) error {
+ if len(errs) == 0 {
+ return nil
+ }
+
+ // `multierror` appends new lines which we need to remove to prevent
+ // blank lines when printing the error.
+ var multiE *multierror.Error
+ multiE = multierror.Append(multiE, errs...)
+ return errors.New(strings.TrimSpace(multiE.ErrorOrNil().Error()))
+}
+
+// ErrorsToString converts the slice of errors into a slice of corresponding
+// error messages.
+func ErrorsToStrings(errs []error) []string {
+ strErrs := make([]string, len(errs))
+ for i := range errs {
+ strErrs[i] = errs[i].Error()
+ }
+ return strErrs
+}
+
+// StringsToErrors converts a slice of error messages into a slice of
+// corresponding errors.
+func StringsToErrors(strErrs []string) []error {
+ errs := make([]error, len(strErrs))
+ for i := range strErrs {
+ errs[i] = errors.New(strErrs[i])
+ }
+ return errs
+}
+
// SyncQuiet syncs a file and logs any error. Should only be used within
// a defer.
func SyncQuiet(f *os.File) {