mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Don't repeat field name in errors
This commit is contained in:
parent
f41c0d0202
commit
15766bfbbc
@ -165,7 +165,7 @@ func NewInvalid(kind, name string, errs fielderrors.ValidationErrorList) error {
|
|||||||
if err, ok := errs[i].(*fielderrors.ValidationError); ok {
|
if err, ok := errs[i].(*fielderrors.ValidationError); ok {
|
||||||
causes = append(causes, api.StatusCause{
|
causes = append(causes, api.StatusCause{
|
||||||
Type: api.CauseType(err.Type),
|
Type: api.CauseType(err.Type),
|
||||||
Message: err.Error(),
|
Message: err.ErrorBody(),
|
||||||
Field: err.Field,
|
Field: err.Field,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -90,12 +90,16 @@ type ValidationError struct {
|
|||||||
var _ error = &ValidationError{}
|
var _ error = &ValidationError{}
|
||||||
|
|
||||||
func (v *ValidationError) Error() string {
|
func (v *ValidationError) Error() string {
|
||||||
|
return fmt.Sprintf("%s: %s", v.Field, v.ErrorBody())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *ValidationError) ErrorBody() string {
|
||||||
var s string
|
var s string
|
||||||
switch v.Type {
|
switch v.Type {
|
||||||
case ValidationErrorTypeRequired, ValidationErrorTypeTooLong:
|
case ValidationErrorTypeRequired, ValidationErrorTypeTooLong:
|
||||||
s = spew.Sprintf("%s: %s", v.Field, v.Type)
|
s = spew.Sprintf("%s", v.Type)
|
||||||
default:
|
default:
|
||||||
s = spew.Sprintf("%s: %s '%+v'", v.Field, v.Type, v.BadValue)
|
s = spew.Sprintf("%s '%+v'", v.Type, v.BadValue)
|
||||||
}
|
}
|
||||||
if len(v.Detail) != 0 {
|
if len(v.Detail) != 0 {
|
||||||
s += fmt.Sprintf(": %s", v.Detail)
|
s += fmt.Sprintf(": %s", v.Detail)
|
||||||
|
Loading…
Reference in New Issue
Block a user