diff --git a/baseapp/abci.go b/baseapp/abci.go index a78fc700bc14..51c6f23a2d85 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -1133,6 +1133,10 @@ func gRPCErrorToSDKError(err error) error { return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) } + if len(status.Details()) > 0 { + err = errorsmod.Wrapf(err, "%v", status.Details()) + } + switch status.Code() { case codes.NotFound: return errorsmod.Wrap(sdkerrors.ErrKeyNotFound, err.Error()) diff --git a/go.mod b/go.mod index 6d117c5f8d12..b17960260d30 100644 --- a/go.mod +++ b/go.mod @@ -46,6 +46,7 @@ require ( github.com/magiconair/properties v1.8.7 github.com/manifoldco/promptui v0.9.0 github.com/mattn/go-isatty v0.0.20 + github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.17.0 github.com/prometheus/common v0.45.0 github.com/rs/zerolog v1.31.0 @@ -59,6 +60,7 @@ require ( golang.org/x/exp v0.0.0-20231006140011-7918f672742d golang.org/x/sync v0.3.0 google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a + google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 google.golang.org/grpc v1.59.0 google.golang.org/protobuf v1.31.0 gotest.tools/v3 v3.5.1 @@ -134,7 +136,6 @@ require ( github.com/oklog/run v1.1.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect @@ -155,7 +156,6 @@ require ( golang.org/x/term v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index 9f4d56a93164..8e3e8631f551 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -5,9 +5,12 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" gogogrpc "github.com/cosmos/gogoproto/grpc" "github.com/golang/protobuf/proto" //nolint:staticcheck // keep legacy for now "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/pkg/errors" + "google.golang.org/genproto/googleapis/rpc/errdetails" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -97,7 +100,7 @@ func (s txServer) Simulate(ctx context.Context, req *txtypes.SimulateRequest) (* gasInfo, result, err := s.simulate(txBytes) if err != nil { - return nil, status.Errorf(codes.Unknown, "%v With gas wanted: '%d' and gas used: '%d' ", err, gasInfo.GasWanted, gasInfo.GasUsed) + return nil, GRPCWrap(err, codes.Unknown, fmt.Sprintf("%v With gas wanted: '%d' and gas used: '%d' ", err, gasInfo.GasWanted, gasInfo.GasUsed)) } return &txtypes.SimulateResponse{ @@ -333,3 +336,27 @@ func parseOrderBy(orderBy txtypes.OrderBy) string { return "" // Defaults to CometBFT's default, which is `asc` now. } } + +func GRPCWrap(err error, c codes.Code, msg string) error { + if err == nil { + return nil + } + + st := status.New(c, msg) + var sdkErr *errorsmod.Error + + if errors.As(err, &sdkErr) { + errorInfo := &errdetails.ErrorInfo{ + Reason: sdkErr.Error(), + Metadata: map[string]string{"Codespace": sdkErr.Codespace(), "ABCICode": fmt.Sprintf("%d", sdkErr.ABCICode())}, + } + + var withDetailsErr error + st, withDetailsErr = st.WithDetails(errorInfo) + if withDetailsErr != nil { + return status.Errorf(c, "%v (failed to add error details: %v)", msg, withDetailsErr) + } + } + + return st.Err() +}