From bf87f0ec68b1e60c36bc94288bda05e052723f77 Mon Sep 17 00:00:00 2001 From: Anastasis Andronidis Date: Mon, 8 Jun 2015 14:06:20 +0200 Subject: [PATCH] Print multiple validation errors --- pkg/kubectl/cmd/util/helpers.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/kubectl/cmd/util/helpers.go b/pkg/kubectl/cmd/util/helpers.go index 8ba64e1b576..92195a75013 100644 --- a/pkg/kubectl/cmd/util/helpers.go +++ b/pkg/kubectl/cmd/util/helpers.go @@ -29,6 +29,7 @@ import ( "strings" "time" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" @@ -56,6 +57,13 @@ func CheckErr(err error) { return } + if errors.IsInvalid(err) { + 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)) + } + // handle multiline errors if clientcmd.IsConfigurationInvalid(err) { fatal(MultilineError("Error in configuration: ", err)) @@ -71,6 +79,14 @@ func CheckErr(err error) { fatal(msg) } +func statusCausesToAggrError(scs []api.StatusCause) utilerrors.Aggregate { + errs := make([]error, len(scs)) + for i, sc := range scs { + errs[i] = fmt.Errorf("%s: %s", sc.Field, sc.Message) + } + return utilerrors.NewAggregate(errs) +} + // StandardErrorMessage translates common errors into a human readable message, or returns // false if the error is not one of the recognized types. It may also log extended // information to glog.