Skip to content

Commit 62a14d6

Browse files
committed
fix(logic): handle and return out of gas error at GRPC level
1 parent 3d87269 commit 62a14d6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

x/logic/keeper/interpreter.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keeper
33
import (
44
"context"
55
"fmt"
6+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
67
"io"
78
"math"
89
"strings"
@@ -107,12 +108,12 @@ func (k Keeper) newInterpreter(ctx context.Context) (*prolog.Interpreter, fmt.St
107108

108109
defer func() {
109110
if r := recover(); r != nil {
110-
if gasError, ok := r.(storetypes.ErrorOutOfGas); ok {
111-
err = engine.ResourceError(prolog2.ResourceGas(gasError.Descriptor, gasMeter.GasConsumed(), gasMeter.Limit()), env)
112-
return
111+
switch rType := r.(type) {
112+
case storetypes.ErrorOutOfGas:
113+
err = errorsmod.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v", rType.Descriptor)
114+
default:
115+
panic(r)
113116
}
114-
115-
panic(r)
116117
}
117118
}()
118119

x/logic/util/prolog.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package util
22

33
import (
44
"context"
5+
errorsmod "cosmossdk.io/errors"
6+
"errors"
7+
sdk "github.com/cosmos/cosmos-sdk/types"
8+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
59
"strings"
610

711
"github.com/ichiban/prolog"
@@ -48,6 +52,12 @@ func QueryInterpreter(
4852
if callErr != nil {
4953
if sdkmath.NewUint(uint64(len(results))).LT(solutionsLimit) {
5054
// error is not part of the look-ahead and should be included in the solutions
55+
if errors.Is(callErr, sdkerrors.ErrOutOfGas) {
56+
return nil, callErr
57+
} else if sdk.UnwrapSDKContext(ctx).GasMeter().IsOutOfGas() {
58+
return nil, errorsmod.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v", callErr.Error())
59+
}
60+
5161
results = append(results, types.Result{Error: callErr.Error()})
5262
} else {
5363
// error is part of the look-ahead, so let's consider that there's one more solution

0 commit comments

Comments
 (0)