Skip to content

Commit

Permalink
return errors immediately instead of appending
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Apr 8, 2022
1 parent 311379f commit ba2196c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions modules/apps/29-fee/types/fee.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -68,19 +66,16 @@ func (f Fee) Total() sdk.Coins {

// Validate asserts that each Fee is valid and all three Fees are not empty or zero
func (fee Fee) Validate() error {
var errFees []string
if !fee.AckFee.IsValid() {
errFees = append(errFees, "ack fee invalid")
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "invalid acknowledgement fee")
}

if !fee.RecvFee.IsValid() {
errFees = append(errFees, "recv fee invalid")
}
if !fee.TimeoutFee.IsValid() {
errFees = append(errFees, "timeout fee invalid")
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "invalid receive fee")
}

if len(errFees) > 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "contains invalid fees: %s", strings.Join(errFees, " , "))
if !fee.TimeoutFee.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "invalid timeout fee")
}

// if all three fee's are zero or empty return an error
Expand Down

0 comments on commit ba2196c

Please sign in to comment.