Handle panics by deferring recover as an error (#345)
* Handle panics by deferring recover as an error * Check for type in recover handler
This commit is contained in:
parent
3b65ddf2b8
commit
a7666f0e7d
1 changed files with 12 additions and 0 deletions
12
script.go
12
script.go
|
@ -219,6 +219,18 @@ func (c *Compiled) RunContext(ctx context.Context) (err error) {
|
|||
v := NewVM(c.bytecode, c.globals, c.maxAllocs)
|
||||
ch := make(chan error, 1)
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
switch e := r.(type) {
|
||||
case string:
|
||||
ch <- fmt.Errorf(e)
|
||||
case error:
|
||||
ch <- e
|
||||
default:
|
||||
ch <- fmt.Errorf("unknown panic: %v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
ch <- v.Run()
|
||||
}()
|
||||
|
||||
|
|
Loading…
Reference in a new issue