Print multiple validation errors

This commit is contained in:
Anastasis Andronidis 2015-06-08 14:06:20 +02:00
parent 51ffa203e3
commit bf87f0ec68

View File

@ -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.