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 24, 2024
1 parent 7c51be8 commit 9982106
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion x/logic/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package interpreter

import (
goctx "context"
"cosmossdk.io/math"
"fmt"
"io"
"io/fs"

"cosmossdk.io/math"

Check failure on line 9 in x/logic/interpreter/interpreter.go

View workflow job for this annotation

GitHub Actions / lint-go

other declaration of math (typecheck)

"github.com/ichiban/prolog"
"github.com/ichiban/prolog/engine"

"cosmossdk.io/math"

Check failure on line 14 in x/logic/interpreter/interpreter.go

View workflow job for this annotation

GitHub Actions / lint-go

`math` redeclared in this block (typecheck)

Check failure on line 14 in x/logic/interpreter/interpreter.go

View workflow job for this annotation

GitHub Actions / lint-go

"cosmossdk.io/math" imported and not used (typecheck)
)

// Option is a function that configures an Interpreter.
Expand Down
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...)
}
8 changes: 5 additions & 3 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
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()
Expand Down

0 comments on commit 9982106

Please sign in to comment.