From f2d1f2377470bb8ca5ac6cf340a95a7579696b03 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Fri, 1 May 2026 07:25:05 +0200 Subject: [PATCH] ast.go: added recover from panic in ast.Eval() --- ast.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ast.go b/ast.go index f22ed9e..8d015d1 100644 --- a/ast.go +++ b/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 {