refactor(x/gov): reduce "if block" indentation (#18918)

This commit is contained in:
lilas
2023-12-30 11:28:11 +00:00
committed by GitHub
parent 4f1d7f92ac
commit 14037aef00
6 changed files with 34 additions and 30 deletions
+4
View File
@@ -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
+3
View File
@@ -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
+2
View File
@@ -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")