Skip to content

Commit

Permalink
interp: recover interpreter internal panics in EvalWithContext
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes committed May 19, 2022
1 parent 00e3f92 commit 821e9ee
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"path"
"path/filepath"
"reflect"
"runtime"
"runtime/debug"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -628,7 +630,14 @@ func (interp *Interpreter) EvalWithContext(ctx context.Context, src string) (ref

done := make(chan struct{})
go func() {
defer close(done)
defer func() {
if r := recover(); r != nil {
var pc [64]uintptr
n := runtime.Callers(1, pc[:])
err = Panic{Value: r, Callers: pc[:n], Stack: debug.Stack()}
}
close(done)
}()
v, err = interp.Eval(src)
}()

Expand Down

0 comments on commit 821e9ee

Please sign in to comment.