@@ -3,6 +3,7 @@ package util
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "fmt"
6
7
"strings"
7
8
8
9
"github.com/axone-protocol/prolog/v2"
@@ -20,6 +21,11 @@ const (
20
21
defaultEnvCap = uint64 (50 )
21
22
)
22
23
24
+ var (
25
+ errMessageVar = engine .NewVariable ()
26
+ errPanicError = engine .Atom ("error" ).Apply (engine .AtomPanicError .Apply (errMessageVar ))
27
+ )
28
+
23
29
// QueryInterpreter interprets a query and returns the solutions up to the given limit.
24
30
//
25
31
//nolint:nestif,funlen
@@ -56,12 +62,14 @@ func QueryInterpreter(
56
62
return nil , callErr
57
63
}
58
64
59
- var panicErr engine.PanicError
60
- if errors .As (callErr , & panicErr ) && errors .Is (panicErr .OriginErr , engine .ErrMaxVariables ) {
61
- return nil , errorsmod .Wrapf (types .LimitExceeded , panicErr .OriginErr .Error ()) //nolint:govet
65
+ var err engine.Exception
66
+ if errors .As (callErr , & err ) {
67
+ if err , ok := isPanicError (err .Term (), env ); ok {
68
+ return nil , errorsmod .Wrapf (types .LimitExceeded , "%s" , err )
69
+ }
62
70
}
63
71
64
- if err = func () error {
72
+ if err : = func () error {
65
73
defer func () {
66
74
_ = recover ()
67
75
}()
@@ -137,3 +145,12 @@ func isBound(v engine.ParsedVariable, env *engine.Env) bool {
137
145
138
146
return ! ok
139
147
}
148
+
149
+ // isPanicError returns the panic error message if the given term is a panic_error.
150
+ func isPanicError (term engine.Term , env * engine.Env ) (string , bool ) {
151
+ if env , ok := env .Unify (term , errPanicError ); ok {
152
+ return fmt .Sprintf ("%s" , env .Resolve (errMessageVar )), true
153
+ }
154
+
155
+ return "" , false
156
+ }
0 commit comments