@@ -3,9 +3,12 @@ package keeper
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
67
78 errorsmod "cosmossdk.io/errors"
9+ storetypes "cosmossdk.io/store/types"
810 sdk "github.com/cosmos/cosmos-sdk/types"
11+ sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
912 "github.com/gnolang/gno/gno.land/pkg/sdk/vm"
1013 "github.com/gnolang/gno/tm2/pkg/std"
1114
@@ -35,6 +38,24 @@ func (k msgServer) Run(ctx context.Context, msg *types.MsgRun) (*types.MsgRunRes
3538 return nil , errorsmod .Wrap (err , "invalid package" )
3639 }
3740
41+ defer func () {
42+ if r := recover (); r != nil {
43+ switch rType := r .(type ) {
44+ case storetypes.ErrorOutOfGas :
45+ log := fmt .Sprintf (
46+ "out of gas from VM usage in location: %v; gasUsed: %d" ,
47+ rType .Descriptor , sdkCtx .GasMeter ().GasConsumed ())
48+
49+ err = errorsmod .Wrap (sdkerrors .ErrOutOfGas , log )
50+ default :
51+ err = fmt .Errorf ("panic while calling VM: %v (%v)" , r , rType )
52+ }
53+ } else {
54+ // this commits the changes to the module store (that is only committed later)
55+ k .VMKeeper .CommitGnoTransactionStore (gnoCtx )
56+ }
57+ }()
58+
3859 resp , err := k .VMKeeper .Run (
3960 gnoCtx ,
4061 vm.MsgRun {
@@ -48,9 +69,6 @@ func (k msgServer) Run(ctx context.Context, msg *types.MsgRun) (*types.MsgRunRes
4869 return nil , errorsmod .Wrap (err , "failed to run VM" )
4970 }
5071
51- // this commits the changes to the module store (that is only committed later)
52- k .VMKeeper .CommitGnoTransactionStore (gnoCtx )
53-
5472 return & types.MsgRunResponse {
5573 Result : string (resp ),
5674 }, nil
0 commit comments