From b7c485ee9a252568c7f1a8ca467d4d60a97cc4f3 Mon Sep 17 00:00:00 2001 From: Anastasis Andronidis Date: Fri, 5 Jun 2015 18:58:18 +0200 Subject: [PATCH] make CheckErr testable --- pkg/kubectl/cmd/util/helpers.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/kubectl/cmd/util/helpers.go b/pkg/kubectl/cmd/util/helpers.go index 92195a75013..a38e04de758 100644 --- a/pkg/kubectl/cmd/util/helpers.go +++ b/pkg/kubectl/cmd/util/helpers.go @@ -53,6 +53,10 @@ type debugError interface { // This method is generic to the command in use and may be used by non-Kubectl // commands. func CheckErr(err error) { + checkErr(err, fatal) +} + +func checkErr(err error, handleErr func(string)) { if err == nil { return } @@ -61,22 +65,22 @@ func CheckErr(err error) { details := err.(*errors.StatusError).Status().Details prefix := fmt.Sprintf("The %s %q is invalid:", details.Kind, details.Name) errs := statusCausesToAggrError(details.Causes) - fatal(MultilineError(prefix, errs)) + handleErr(MultilineError(prefix, errs)) } // handle multiline errors if clientcmd.IsConfigurationInvalid(err) { - fatal(MultilineError("Error in configuration: ", err)) + handleErr(MultilineError("Error in configuration: ", err)) } if agg, ok := err.(utilerrors.Aggregate); ok && len(agg.Errors()) > 0 { - fatal(MultipleErrors("", agg.Errors())) + handleErr(MultipleErrors("", agg.Errors())) } msg, ok := StandardErrorMessage(err) if !ok { msg = fmt.Sprintf("error: %s\n", err.Error()) } - fatal(msg) + handleErr(msg) } func statusCausesToAggrError(scs []api.StatusCause) utilerrors.Aggregate {