Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(abci): add unwrapper to handle join error #23712

Open
wants to merge 4 commits into
base: release/v0.50.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/sha256"
"errors"
"fmt"
"math/rand"
"testing"
Expand Down Expand Up @@ -32,6 +33,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
)

Expand Down Expand Up @@ -883,3 +885,26 @@ func TestLoadVersionPruning(t *testing.T) {
require.Nil(t, err)
testLoadVersionHelper(t, app, int64(7), lastCommitID)
}

func TestErrorsJoinAndABCIInfo(t *testing.T) {
tErr := sdkerrors.ErrInsufficientFunds
tErrCode := tErr.ABCICode()
tests := []struct {
name string
err error
exp uint32
}{
{name: "nil", err: nil, exp: 0},
{name: "ErrInsufficientFunds", err: tErr, exp: tErrCode},
{name: "joined ErrInsufficientFunds", err: errors.Join(tErr), exp: tErrCode},
{name: "joined nil ErrInsufficientFunds", err: errors.Join(nil, tErr), exp: tErrCode},
{name: "joined ErrInsufficientFunds nil", err: errors.Join(tErr, nil), exp: tErrCode},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
_, act, _ := errorsmod.ABCIInfo(tc.err, false)
require.Equal(t, int(tc.exp), int(act))
})
}
}
10 changes: 10 additions & 0 deletions errors/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func abciCode(err error) uint32 {
}

for {
if c, ok := err.(interface{ Unwrap() []error }); ok {
errs := c.Unwrap()
for _, e := range errs {
if e != nil {
err = e
break
}
}
}

if c, ok := err.(coder); ok {
return c.ABCICode()
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ replace (
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)

replace cosmossdk.io/errors => ./errors

retract (
// false start by tagging the wrong branch
v0.50.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=
cosmossdk.io/core v0.11.0/go.mod h1:LaTtayWBSoacF5xNzoF8tmLhehqlA9z1SWiPuNC6X1w=
cosmossdk.io/depinject v1.1.0 h1:wLan7LG35VM7Yo6ov0jId3RHWCGRhe8E8bsuARorl5E=
cosmossdk.io/depinject v1.1.0/go.mod h1:kkI5H9jCGHeKeYWXTqYdruogYrEeWvBQCw1Pj4/eCFI=
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
Expand Down
Loading