You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a method would make it clear what we are comparing with (nicer notation?).
Comparison with ErrInternal would be possible to implement (requires more changes).
Change how errors comparison is implemented
Current implementation is mostly comparing the ABCI Code value. This is limiting the error testing and prevents from implementing ErrInternal comparison.
Instead of the current implementation the following one could be used.
// Is returns true if given error or its cause is the same kind.// If cause error provides Cause method then a comparison is made with all// parents as well.func (kind*Error) Is(errerror) bool {
typecauserinterface {
Cause() error
}
for {
iferr==kind {
returntrue
}
ife, ok:=err.(causer); ok {
err=e.Cause()
} else {
returnfalse
}
}
}
Our error instances are global and therefore comparable as instances. Using the above mechanism would also allow to "inherit" errors. Below can be true.
root:=Wrap(nil, "root")
child1:=Wrap(root, "child one")
child2:=Wrap(root, "child two")
fmt.Println("child 1 is root", root.Is(child1))
// child 1 is root truefmt.Println("child 2 is root", root.Is(child2))
// child 2 is root truefmt.Println("root is child 1", child1.Is(root))
// root is child 1 falsefmt.Println("child 2 is child 1", child1.Is(child2))
// child 2 is child 1 false
These can both be tackled together and since we always compare against an intention (and not "any random error is ErrInternal"), this makes more sense
The text was updated successfully, but these errors were encountered:
Based on part of #368
Replace
Is
function withError.Is
method.Currently to check an error type,
Is
function must be used.After making
Is
a method, above example would beErrInternal
would be possible to implement (requires more changes).Change how errors comparison is implemented
Current implementation is mostly comparing the ABCI Code value. This is limiting the error testing and prevents from implementing
ErrInternal
comparison.Instead of the current implementation the following one could be used.
Our error instances are global and therefore comparable as instances. Using the above mechanism would also allow to "inherit" errors. Below can be true.
These can both be tackled together and since we always compare against an intention (and not "any random error is ErrInternal"), this makes more sense
The text was updated successfully, but these errors were encountered: