Skip to content

Commit

Permalink
Shorten names for better reading
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Dec 10, 2015
1 parent 87a3504 commit 7fb8f60
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 284 deletions.
2 changes: 1 addition & 1 deletion examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
}
errors = expvalidation.ValidateDaemonSet(t)
default:
return field.ErrorList{field.NewInternalError(field.NewPath(""), fmt.Errorf("no validation defined for %#v", obj))}
return field.ErrorList{field.InternalError(field.NewPath(""), fmt.Errorf("no validation defined for %#v", obj))}
}
return errors
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestNewInvalid(t *testing.T) {
Details *unversioned.StatusDetails
}{
{
field.NewDuplicateError(field.NewPath("field[0].name"), "bar"),
field.Duplicate(field.NewPath("field[0].name"), "bar"),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
Expand All @@ -103,7 +103,7 @@ func TestNewInvalid(t *testing.T) {
},
},
{
field.NewInvalidError(field.NewPath("field[0].name"), "bar", "detail"),
field.Invalid(field.NewPath("field[0].name"), "bar", "detail"),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
Expand All @@ -114,7 +114,7 @@ func TestNewInvalid(t *testing.T) {
},
},
{
field.NewNotFoundError(field.NewPath("field[0].name"), "bar"),
field.NotFound(field.NewPath("field[0].name"), "bar"),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
Expand All @@ -125,7 +125,7 @@ func TestNewInvalid(t *testing.T) {
},
},
{
field.NewNotSupportedError(field.NewPath("field[0].name"), "bar", nil),
field.NotSupported(field.NewPath("field[0].name"), "bar", nil),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
Expand All @@ -136,7 +136,7 @@ func TestNewInvalid(t *testing.T) {
},
},
{
field.NewRequiredError(field.NewPath("field[0].name")),
field.Required(field.NewPath("field[0].name")),
&unversioned.StatusDetails{
Kind: "kind",
Name: "name",
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/rest/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func validateCommonFields(obj, old runtime.Object) field.ErrorList {
allErrs := field.ErrorList{}
objectMeta, err := api.ObjectMetaFor(obj)
if err != nil {
return append(allErrs, field.NewInternalError(field.NewPath("metadata"), err))
return append(allErrs, field.InternalError(field.NewPath("metadata"), err))
}
oldObjectMeta, err := api.ObjectMetaFor(old)
if err != nil {
return append(allErrs, field.NewInternalError(field.NewPath("metadata"), err))
return append(allErrs, field.InternalError(field.NewPath("metadata"), err))
}
allErrs = append(allErrs, validation.ValidateObjectMetaUpdate(objectMeta, oldObjectMeta, field.NewPath("metadata"))...)

Expand Down
6 changes: 3 additions & 3 deletions pkg/api/validation/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func ValidateEvent(event *api.Event) field.ErrorList {
// There is no namespace required for node.
if event.InvolvedObject.Kind == "Node" &&
event.Namespace != "" {
allErrs = append(allErrs, field.NewInvalidError(field.NewPath("involvedObject", "namespace"), event.InvolvedObject.Namespace, "not required for node"))
allErrs = append(allErrs, field.Invalid(field.NewPath("involvedObject", "namespace"), event.InvolvedObject.Namespace, "not required for node"))
}
if event.InvolvedObject.Kind != "Node" &&
event.Namespace != event.InvolvedObject.Namespace {
allErrs = append(allErrs, field.NewInvalidError(field.NewPath("involvedObject", "namespace"), event.InvolvedObject.Namespace, "does not match involvedObject"))
allErrs = append(allErrs, field.Invalid(field.NewPath("involvedObject", "namespace"), event.InvolvedObject.Namespace, "does not match involvedObject"))
}
if !validation.IsDNS1123Subdomain(event.Namespace) {
allErrs = append(allErrs, field.NewInvalidError(field.NewPath("namespace"), event.Namespace, ""))
allErrs = append(allErrs, field.Invalid(field.NewPath("namespace"), event.Namespace, ""))
}
return allErrs
}
378 changes: 189 additions & 189 deletions pkg/api/validation/validation.go

Large diffs are not rendered by default.

98 changes: 49 additions & 49 deletions pkg/apis/extensions/validation/validation.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/util/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ func TestCheckInvalidErr(t *testing.T) {
expected string
}{
{
errors.NewInvalid("Invalid1", "invalidation", field.ErrorList{field.NewInvalidError(field.NewPath("field"), "single", "details")}),
errors.NewInvalid("Invalid1", "invalidation", field.ErrorList{field.Invalid(field.NewPath("field"), "single", "details")}),
`Error from server: Invalid1 "invalidation" is invalid: field: invalid value 'single', Details: details`,
},
{
errors.NewInvalid("Invalid2", "invalidation", field.ErrorList{field.NewInvalidError(field.NewPath("field1"), "multi1", "details"), field.NewInvalidError(field.NewPath("field2"), "multi2", "details")}),
errors.NewInvalid("Invalid2", "invalidation", field.ErrorList{field.Invalid(field.NewPath("field1"), "multi1", "details"), field.Invalid(field.NewPath("field2"), "multi2", "details")}),
`Error from server: Invalid2 "invalidation" is invalid: [field1: invalid value 'multi1', Details: details, field2: invalid value 'multi2', Details: details]`,
},
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func filterInvalidPods(pods []*api.Pod, source string, recorder record.EventReco
if names.Has(name) {
// TODO: when validation becomes versioned, this gets a bit
// more complicated.
errlist = append(errlist, field.NewDuplicateError(field.NewPath("metadata", "name"), pod.Name))
errlist = append(errlist, field.Duplicate(field.NewPath("metadata", "name"), pod.Name))
} else {
names.Insert(name)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/pod/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ func (r *BindingREST) Create(ctx api.Context, obj runtime.Object) (out runtime.O
// TODO: move me to a binding strategy
if len(binding.Target.Kind) != 0 && binding.Target.Kind != "Node" {
// TODO: When validation becomes versioned, this gets more complicated.
return nil, errors.NewInvalid("binding", binding.Name, field.ErrorList{field.NewNotSupportedError(field.NewPath("target", "kind"), binding.Target.Kind, []string{"Node", ""})})
return nil, errors.NewInvalid("binding", binding.Name, field.ErrorList{field.NotSupported(field.NewPath("target", "kind"), binding.Target.Kind, []string{"Node", ""})})
}
if len(binding.Target.Name) == 0 {
// TODO: When validation becomes versioned, this gets more complicated.
return nil, errors.NewInvalid("binding", binding.Name, field.ErrorList{field.NewRequiredError(field.NewPath("target", "name"))})
return nil, errors.NewInvalid("binding", binding.Name, field.ErrorList{field.Required(field.NewPath("target", "name"))})
}
err = r.assignPod(ctx, binding.Name, binding.Target.Name, binding.Annotations)
out = &unversioned.Status{Status: unversioned.StatusSuccess}
Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/service/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
// Try to respect the requested IP.
if err := rs.serviceIPs.Allocate(net.ParseIP(service.Spec.ClusterIP)); err != nil {
// TODO: when validation becomes versioned, this gets more complicated.
el := field.ErrorList{field.NewInvalidError(field.NewPath("spec", "clusterIP"), service.Spec.ClusterIP, err.Error())}
el := field.ErrorList{field.Invalid(field.NewPath("spec", "clusterIP"), service.Spec.ClusterIP, err.Error())}
return nil, errors.NewInvalid("Service", service.Name, el)
}
releaseServiceIP = true
Expand All @@ -108,7 +108,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
err := nodePortOp.Allocate(servicePort.NodePort)
if err != nil {
// TODO: when validation becomes versioned, this gets more complicated.
el := field.ErrorList{field.NewInvalidError(field.NewPath("spec", "ports").Index(i).Child("nodePort"), servicePort.NodePort, err.Error())}
el := field.ErrorList{field.Invalid(field.NewPath("spec", "ports").Index(i).Child("nodePort"), servicePort.NodePort, err.Error())}
return nil, errors.NewInvalid("Service", service.Name, el)
}
} else if assignNodePorts {
Expand Down Expand Up @@ -229,7 +229,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
if !contains(oldNodePorts, nodePort) {
err := nodePortOp.Allocate(nodePort)
if err != nil {
el := field.ErrorList{field.NewInvalidError(field.NewPath("spec", "ports").Index(i).Child("nodePort"), nodePort, err.Error())}
el := field.ErrorList{field.Invalid(field.NewPath("spec", "ports").Index(i).Child("nodePort"), nodePort, err.Error())}
return nil, false, errors.NewInvalid("Service", service.Name, el)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ParseWatchResourceVersion(resourceVersion string) (uint64, error) {
return 0, errors.NewInvalid("", "", field.ErrorList{
// Validation errors are supposed to return version-specific field
// paths, but this is probably close enough.
field.NewInvalidError(field.NewPath("resourceVersion"), resourceVersion, err.Error()),
field.Invalid(field.NewPath("resourceVersion"), resourceVersion, err.Error()),
})
}
return version + 1, nil
Expand Down
26 changes: 13 additions & 13 deletions pkg/util/validation/field/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ const (
// NewRequiredError.
ErrorTypeRequired ErrorType = "FieldValueRequired"
// ErrorTypeDuplicate is used to report collisions of values that must be
// unique (e.g. unique IDs). See NewDuplicateError.
// unique (e.g. unique IDs). See Duplicate().
ErrorTypeDuplicate ErrorType = "FieldValueDuplicate"
// ErrorTypeInvalid is used to report malformed values (e.g. failed regex
// match, too long, out of bounds). See NewInvalidError.
// match, too long, out of bounds). See Invalid().
ErrorTypeInvalid ErrorType = "FieldValueInvalid"
// ErrorTypeNotSupported is used to report unknown values for enumerated
// fields (e.g. a list of valid values). See NewNotSupportedError.
// fields (e.g. a list of valid values). See NotSupported().
ErrorTypeNotSupported ErrorType = "FieldValueNotSupported"
// ErrorTypeForbidden is used to report valid (as per formatting rules)
// values which would be accepted under some conditions, but which are not
// permitted by the current conditions (such as security policy). See
// NewForbiddenError.
// Forbidden().
ErrorTypeForbidden ErrorType = "FieldValueForbidden"
// ErrorTypeTooLong is used to report that the given value is too long.
// This is similar to ErrorTypeInvalid, but the error will not include the
// too-long value. See NewTooLongError.
// too-long value. See TooLong().
ErrorTypeTooLong ErrorType = "FieldValueTooLong"
// ErrorTypeInternal is used to report other errors that are not related
// to user input.
Expand Down Expand Up @@ -121,33 +121,33 @@ func (t ErrorType) String() string {

// NewNotFoundError returns a *Error indicating "value not found". This is
// used to report failure to find a requested value (e.g. looking up an ID).
func NewNotFoundError(field *Path, value interface{}) *Error {
func NotFound(field *Path, value interface{}) *Error {
return &Error{ErrorTypeNotFound, field.String(), value, ""}
}

// NewRequiredError returns a *Error indicating "value required". This is used
// to report required values that are not provided (e.g. empty strings, null
// values, or empty arrays).
func NewRequiredError(field *Path) *Error {
func Required(field *Path) *Error {
return &Error{ErrorTypeRequired, field.String(), "", ""}
}

// NewDuplicateError returns a *Error indicating "duplicate value". This is
// used to report collisions of values that must be unique (e.g. names or IDs).
func NewDuplicateError(field *Path, value interface{}) *Error {
func Duplicate(field *Path, value interface{}) *Error {
return &Error{ErrorTypeDuplicate, field.String(), value, ""}
}

// NewInvalidError returns a *Error indicating "invalid value". This is used
// to report malformed values (e.g. failed regex match, too long, out of bounds).
func NewInvalidError(field *Path, value interface{}, detail string) *Error {
func Invalid(field *Path, value interface{}, detail string) *Error {
return &Error{ErrorTypeInvalid, field.String(), value, detail}
}

// NewNotSupportedError returns a *Error indicating "unsupported value".
// This is used to report unknown values for enumerated fields (e.g. a list of
// valid values).
func NewNotSupportedError(field *Path, value interface{}, validValues []string) *Error {
func NotSupported(field *Path, value interface{}, validValues []string) *Error {
detail := ""
if validValues != nil && len(validValues) > 0 {
detail = "supported values: " + strings.Join(validValues, ", ")
Expand All @@ -159,22 +159,22 @@ func NewNotSupportedError(field *Path, value interface{}, validValues []string)
// report valid (as per formatting rules) values which would be accepted under
// some conditions, but which are not permitted by current conditions (e.g.
// security policy).
func NewForbiddenError(field *Path, value interface{}) *Error {
func Forbidden(field *Path, value interface{}) *Error {
return &Error{ErrorTypeForbidden, field.String(), value, ""}
}

// NewTooLongError returns a *Error indicating "too long". This is used to
// report that the given value is too long. This is similar to
// NewInvalidError, but the returned error will not include the too-long
// value.
func NewTooLongError(field *Path, value interface{}, maxLength int) *Error {
func TooLong(field *Path, value interface{}, maxLength int) *Error {
return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d characters", maxLength)}
}

// NewInternalError returns a *Error indicating "internal error". This is used
// to signal that an error was found that was not directly related to user
// input. The err argument must be non-nil.
func NewInternalError(field *Path, err error) *Error {
func InternalError(field *Path, err error) *Error {
return &Error{ErrorTypeInternal, field.String(), nil, err.Error()}
}

Expand Down
26 changes: 13 additions & 13 deletions pkg/util/validation/field/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ func TestMakeFuncs(t *testing.T) {
expected ErrorType
}{
{
func() *Error { return NewInvalidError(NewPath("f"), "v", "d") },
func() *Error { return Invalid(NewPath("f"), "v", "d") },
ErrorTypeInvalid,
},
{
func() *Error { return NewNotSupportedError(NewPath("f"), "v", nil) },
func() *Error { return NotSupported(NewPath("f"), "v", nil) },
ErrorTypeNotSupported,
},
{
func() *Error { return NewDuplicateError(NewPath("f"), "v") },
func() *Error { return Duplicate(NewPath("f"), "v") },
ErrorTypeDuplicate,
},
{
func() *Error { return NewNotFoundError(NewPath("f"), "v") },
func() *Error { return NotFound(NewPath("f"), "v") },
ErrorTypeNotFound,
},
{
func() *Error { return NewRequiredError(NewPath("f")) },
func() *Error { return Required(NewPath("f")) },
ErrorTypeRequired,
},
{
func() *Error { return NewInternalError(NewPath("f"), fmt.Errorf("e")) },
func() *Error { return InternalError(NewPath("f"), fmt.Errorf("e")) },
ErrorTypeInternal,
},
}
Expand All @@ -62,7 +62,7 @@ func TestMakeFuncs(t *testing.T) {
}

func TestErrorUsefulMessage(t *testing.T) {
s := NewInvalidError(NewPath("foo"), "bar", "deet").Error()
s := Invalid(NewPath("foo"), "bar", "deet").Error()
t.Logf("message: %v", s)
for _, part := range []string{"foo", "bar", "deet", ErrorTypeInvalid.String()} {
if !strings.Contains(s, part) {
Expand All @@ -76,7 +76,7 @@ func TestErrorUsefulMessage(t *testing.T) {
Inner interface{}
KV map[string]int
}
s = NewInvalidError(
s = Invalid(
NewPath("foo"),
&complicated{
Baz: 1,
Expand All @@ -102,8 +102,8 @@ func TestToAggregate(t *testing.T) {
testCases := []ErrorList{
nil,
{},
{NewInvalidError(NewPath("f"), "v", "d")},
{NewInvalidError(NewPath("f"), "v", "d"), NewInternalError(NewPath(""), fmt.Errorf("e"))},
{Invalid(NewPath("f"), "v", "d")},
{Invalid(NewPath("f"), "v", "d"), InternalError(NewPath(""), fmt.Errorf("e"))},
}
for i, tc := range testCases {
agg := tc.ToAggregate()
Expand All @@ -121,9 +121,9 @@ func TestToAggregate(t *testing.T) {

func TestErrListFilter(t *testing.T) {
list := ErrorList{
NewInvalidError(NewPath("test.field"), "", ""),
NewInvalidError(NewPath("field.test"), "", ""),
NewDuplicateError(NewPath("test"), "value"),
Invalid(NewPath("test.field"), "", ""),
Invalid(NewPath("field.test"), "", ""),
Duplicate(NewPath("test"), "value"),
}
if len(list.Filter(NewErrorTypeMatcher(ErrorTypeDuplicate))) != 2 {
t.Errorf("should not filter")
Expand Down

0 comments on commit 7fb8f60

Please sign in to comment.