Commit Graph

12 Commits

Author SHA1 Message Date
mattmoor-sockpuppet 4f143e6ce3 golang format tools (#263)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
2019-02-07 08:17:41 -08:00
Victor Agababov 819ebda80c Add `AtIndex` method to deal to attach index at the current error. (#257)
* Add `AtIndex` method to deal to attach index at the current error.

This is useful when we are dealing with primite leaf list (e.g.
a list of strings).
The alternative are
a) creating dummy error and then executing ViaFieldIndex(), which is
plain ugly
b) implementing Validate() on the primitive type via type aliasing and
then collecting errors, which seems an overkill.

In addition it seems ViaFieldIndex was not covered by unit tests,
so I've added one to take care of that.

* implement suggestions from the review

* cleanup

* cosmetic

* cosmetic
2019-01-31 12:47:38 -08:00
Victor Agababov 1f624b77dd Some clean ups in the FieldError code and its tests. (#194)
* Some clean ups in the FieldError code and its tests.

- rename FieldError.getNormalizedError to be normalized:
  - Go kind of discourages GetA() vs A()
  - it's an error, so normalizing itself is also an error, so
    normalizedError() is a tautology at this point
- flatten was doing a[x]=fmt.Sprintf("%s%s", a[x],y), which is a very
  expensive substitution for a[x]+=y
- some minor test cleanups (fix strings, streamline `got, want:=`
  pattern, etc.

* Also make normalize() and merge() operate on pointers.

As the code currently is structured we are doing lots of duplication
and copies of the objects, since we're doing []FieldError throughout
normalize() and merge() even though normalize already returns a copy of
the initial error tree, rather than a list of pointers to existing
errors.

Hence list returned by normalize() and hence merge() can actually be pointer
lists which would save us some CPU and memory.
2018-12-06 17:06:26 -08:00
Kenny Leung 3e52d67e3d Add ErrOutOfBoundsValue for value boundary validation (#167) 2018-11-13 17:36:45 -08:00
Scott Nichols 5a67e38d13 Simplify FieldError merging. (#99)
* checkpoint.

* Tried a new way.

* Some more slimplifying based on feedback.

* use bang vs == false.

* not sure why I did not use go style on this forloop, fixed.
2018-10-30 01:20:33 -07:00
Scott Nichols 7aae4072d7 Sort keys and paths for FieldError. (#90) 2018-09-24 15:48:20 -07:00
Scott Nichols a133825579 Adding also always to return nil for nil errors (#83) 2018-09-20 15:00:19 -07:00
Scott Nichols 70762ec49b Reintroduce FieldError (#77)
* Testing an idea for field errors.

* wrap other tests for webhook.

* move FieldError to Error, FieldErrors to FieldError

* Rename files to reflect their type.

* Reworked this to require no changes externally.

* test also.

* gotta cover those tests.

* nil check

* Adding Also.

* Clean up comments.

* Don't delete the tests.

* Null check test the clear.

* Fix nits.

* FieldError is now non-mutating.

* More errorf formatting fixes.

* I can make this even simpiler

* I can make this even MORE simpiler

* Add comment to make flow of also clear.

* fix comment, optimize make errors
2018-09-20 09:24:19 -07:00
Scott Nichols f0ec8c5ac7 Adding ViaIndex, ViaKey, ViaFieldIndex, ViaFieldKey to FieldErrors (#55)
* Adding .ViaIndex(1). to make spec.param[1] easier to do.

* Adding ViaKey

* fix order of bag example.

* Add code coverage to missed line.

* Adding ViaFieldIndex helper

* cleaning up.

* compress more.

* more cleanup

* test name
2018-09-14 21:07:17 -07:00
Scott Nichols 5182837041 flipped the error text around. fixed. (#36) 2018-08-02 13:13:38 -07:00
Scott Nichols c1e9219cee Adding more field errors. (#34)
* Adding mutually exclusive fields error.

* Adding ErrMissingOneOf, ErrMultipleOneOf, ErrInvalidParameterName

* Adding gitignore.

* Change to ErrInvalidKeyName.

* Use ... semantic.

* those pesky newlines.
2018-08-02 10:05:37 -07:00
Matt Moore 945c05cc41
Bring in the API utilities from `pkg/apis/serving/v1alpha1` used for validation and defaulting in the webhook. (#13)
Fixes: https://github.com/knative/pkg/issues/12
2018-07-26 12:14:57 -07:00