Skip to content

Commit

Permalink
feat: handle MaxVariables error limit exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Jul 25, 2024
1 parent e84c67c commit 040a765
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions x/logic/interpreter/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion x/logic/prolog/tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
6 changes: 4 additions & 2 deletions x/logic/util/prolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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()
Expand Down

0 comments on commit 040a765

Please sign in to comment.