ast.go: added recover from panic in ast.Eval()

This commit is contained in:
Celestino Amoroso 2026-05-01 07:25:05 +02:00
parent edd90054d7
commit f2d1f23774

12
ast.go
View File

@ -5,6 +5,7 @@
package expr package expr
import ( import (
"errors"
"strings" "strings"
"git.portale-stac.it/go-pkg/expr/kern" "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) { 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() ast.Finish()
if ast.root != nil { if ast.root != nil {