From 9982106fd8923d462a851b60384fb3d2de11d9c7 Mon Sep 17 00:00:00 2001 From: Benjamin DENEUX Date: Wed, 24 Jul 2024 14:19:02 +0200 Subject: [PATCH] feat: handle MaxVariables error limit exceeded --- x/logic/interpreter/interpreter.go | 5 ++++- x/logic/interpreter/registry.go | 5 +++-- x/logic/prolog/tuple.go | 2 +- x/logic/util/prolog.go | 8 +++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/x/logic/interpreter/interpreter.go b/x/logic/interpreter/interpreter.go index 7224c4bb5..cb20e0c73 100644 --- a/x/logic/interpreter/interpreter.go +++ b/x/logic/interpreter/interpreter.go @@ -2,13 +2,16 @@ package interpreter import ( goctx "context" - "cosmossdk.io/math" "fmt" "io" "io/fs" + "cosmossdk.io/math" + "github.com/ichiban/prolog" "github.com/ichiban/prolog/engine" + + "cosmossdk.io/math" ) // Option is a function that configures an Interpreter. diff --git a/x/logic/interpreter/registry.go b/x/logic/interpreter/registry.go index 45b887470..d019bcf93 100644 --- a/x/logic/interpreter/registry.go +++ b/x/logic/interpreter/registry.go @@ -2,12 +2,13 @@ package interpreter import ( "fmt" - orderedmap "github.com/wk8/go-ordered-map/v2" "strconv" "strings" + orderedmap "github.com/wk8/go-ordered-map/v2" + "github.com/ichiban/prolog" - engine "github.com/ichiban/prolog/engine" + "github.com/ichiban/prolog/engine" "github.com/axone-protocol/axoned/v8/x/logic/predicate" ) diff --git a/x/logic/prolog/tuple.go b/x/logic/prolog/tuple.go index c7d41903f..3fca45744 100644 --- a/x/logic/prolog/tuple.go +++ b/x/logic/prolog/tuple.go @@ -4,5 +4,5 @@ import "github.com/ichiban/prolog/engine" // Tuple is a predicate which unifies the given term with a tuple of the given arity. func Tuple(args ...engine.Term) engine.Term { - return engine.Atom(0).Apply(args...) + return engine.Atom("").Apply(args...) } diff --git a/x/logic/util/prolog.go b/x/logic/util/prolog.go index 05807bfe7..00ebba2cb 100644 --- a/x/logic/util/prolog.go +++ b/x/logic/util/prolog.go @@ -54,16 +54,18 @@ func QueryInterpreter( // error is not part of the look-ahead and should be included in the solutions sdkCtx := sdk.UnwrapSDKContext(ctx) + var panicErr engine.PanicError switch { case errors.Is(callErr, types.LimitExceeded): - return nil, callErr + return nil, err + case errors.As(callErr, &panicErr) && errors.Is(panicErr.OriginErr, engine.ErrMaxVariables): + return nil, errorsmod.Wrapf(types.LimitExceeded, panicErr.OriginErr.Error()) case sdkCtx.GasMeter().IsOutOfGas(): return nil, errorsmod.Wrapf( types.LimitExceeded, "out of gas: %s <%s> (%d/%d)", types.ModuleName, callErr.Error(), sdkCtx.GasMeter().GasConsumed(), sdkCtx.GasMeter().Limit()) - default: - results = append(results, types.Result{Error: callErr.Error()}) } + results = append(results, types.Result{Error: callErr.Error()}) } else { // error is part of the look-ahead, so let's consider that there's one more solution count = count.Incr()