feat: adds error handling for out-of-gas panics in grpc query handlers. (#20945)
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
@@ -67,6 +68,18 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
|
||||
|
||||
app.logger.Debug("gRPC query received of type: " + fmt.Sprintf("%#v", req))
|
||||
|
||||
// Catch an OutOfGasPanic caused in the query handlers
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
switch rType := r.(type) {
|
||||
case storetypes.ErrorOutOfGas:
|
||||
err = errorsmod.Wrapf(sdkerrors.ErrOutOfGas, "Query gas limit exceeded: %v, out of gas in location: %v", sdkCtx.GasMeter().Limit(), rType.Descriptor)
|
||||
default:
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return handler(grpcCtx, req)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user