MCPcopy Create free account
hub / github.com/cockroachdb/errors / If

Function If

markers/markers.go:151–158  ·  view source on GitHub ↗

If iterates on the error's causal chain and returns a predicate's return value the first time the predicate returns true. Note: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to If().

(err error, pred func(err error) (interface{}, bool))

Source from the content-addressed store, hash-verified

149// package location or a different type, ensure that
150// RegisterTypeMigration() was called prior to If().
151func If(err error, pred func(err error) (interface{}, bool)) (interface{}, bool) {
152 for c := err; c != nil; c = errbase.UnwrapOnce(c) {
153 if v, ok := pred(c); ok {
154 return v, ok
155 }
156 }
157 return nil, false
158}
159
160// IsAny is like Is except that multiple references are compared.
161//

Callers 10

IfFunction · 0.92
TestIssueLinkFunction · 0.92
HasIssueLinkFunction · 0.92
TestUnimplementedErrorFunction · 0.92
GetGrpcCodeFunction · 0.92
TestAssertFunction · 0.92
HasAssertionFailureFunction · 0.92
GetHTTPCodeFunction · 0.92
HasTypeFunction · 0.70
HasInterfaceFunction · 0.70

Calls 1

UnwrapOnceFunction · 0.92

Tested by 3

TestIssueLinkFunction · 0.74
TestUnimplementedErrorFunction · 0.74
TestAssertFunction · 0.74