refactor(x/gov): reduce "if block" indentation (#18918)
This commit is contained in:
@@ -31,6 +31,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Improvements
|
||||
|
||||
* [#18918](https://github.com/cosmos/cosmos-sdk/pull/18918) Improve `IsOf` by returning earlier when the checked error is nil.
|
||||
|
||||
## [v1.0.0](https://github.com/cosmos/cosmos-sdk/releases/tag/errors%2Fv1.0.0)
|
||||
|
||||
### Features
|
||||
|
||||
@@ -284,6 +284,9 @@ func WithType(err error, obj interface{}) error {
|
||||
// IsOf checks if a received error is caused by one of the target errors.
|
||||
// It extends the errors.Is functionality to a list of errors.
|
||||
func IsOf(received error, targets ...error) bool {
|
||||
if received == nil {
|
||||
return false
|
||||
}
|
||||
for _, t := range targets {
|
||||
if errors.Is(received, t) {
|
||||
return true
|
||||
|
||||
@@ -118,6 +118,8 @@ func (s *errorsTestSuite) TestIsOf() {
|
||||
err := ErrInvalidAddress
|
||||
errW := Wrap(ErrLogic, "more info")
|
||||
|
||||
require.False(IsOf(nil), "nil should always have no causer")
|
||||
require.False(IsOf(nil, err), "nil should always have no causer")
|
||||
require.False(IsOf(errNil), "nil error should always have no causer")
|
||||
require.False(IsOf(errNil, err), "nil error should always have no causer")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user