ast.go: added recover from panic in ast.Eval()
This commit is contained in:
parent
edd90054d7
commit
f2d1f23774
12
ast.go
12
ast.go
@ -5,6 +5,7 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
@ -106,6 +107,17 @@ func (ast *ast) Finish() {
|
||||
}
|
||||
|
||||
func (ast *ast) Eval(ctx kern.ExprContext) (result any, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if errVal, ok := r.(error); ok {
|
||||
err = errVal
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
err = errors.New("unexpected error while evaluating the expression")
|
||||
}
|
||||
}()
|
||||
|
||||
ast.Finish()
|
||||
|
||||
if ast.root != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user