File tree Expand file tree Collapse file tree 5 files changed +1252
-0
lines changed Expand file tree Collapse file tree 5 files changed +1252
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ require (
1111 github.com/rancher/lasso v0.0.0-20230629200414-8a54b32e6792
1212 github.com/sirupsen/logrus v1.9.0
1313 github.com/stretchr/testify v1.8.2
14+ golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
1415 golang.org/x/sync v0.2.0
1516 golang.org/x/text v0.11.0
1617 golang.org/x/tools v0.8.0
Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
113113golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 /go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w =
114114golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 /go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI =
115115golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 /go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto =
116+ golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA =
117+ golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e /go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA =
116118golang.org/x/mod v0.2.0 /go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA =
117119golang.org/x/mod v0.3.0 /go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA =
118120golang.org/x/mod v0.4.2 /go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA =
Original file line number Diff line number Diff line change 1+ package data
2+
3+ type errorCode int
4+
5+ const (
6+ errorInvalidData errorCode = iota + 1
7+ errorInvalidField
8+ errorFieldValueNotFound
9+ )
10+
11+ type DataError struct {
12+ message string
13+ code errorCode
14+ }
15+
16+ // Error returns the underlying error message, satisfying the error interface
17+ func (d * DataError ) Error () string {
18+ return d .message
19+ }
20+
21+ func newDataError (message string , code errorCode ) * DataError {
22+ return & DataError {
23+ message : message ,
24+ code : code ,
25+ }
26+ }
27+
28+ // IsInvalidDataError checks if a given error indicates that the provided data field was invalid.
29+ func IsInvalidDataError (err error ) bool {
30+ return checkErrTypeAndCode (err , errorInvalidData )
31+ }
32+
33+ // IsInvalidFieldError checks if a given error indicates that the provided field was invalid.
34+ func IsInvalidFieldError (err error ) bool {
35+ return checkErrTypeAndCode (err , errorInvalidField )
36+ }
37+
38+ // IsFieldValueNotFoundError checks if a given error indicates that the provided field was not found in the provided
39+ // data.
40+ func IsFieldValueNotFoundError (err error ) bool {
41+ return checkErrTypeAndCode (err , errorFieldValueNotFound )
42+ }
43+
44+ func checkErrTypeAndCode (err error , code errorCode ) bool {
45+ dataErr , ok := err .(* DataError )
46+ if ! ok {
47+ return false
48+ }
49+ return dataErr .code == code
50+ }
You can’t perform that action at this time.
0 commit comments