bencode.Decoder.Decode: Don't assume panic values are type error

This commit is contained in:
Matt Joiner 2018-02-13 00:55:15 +11:00
parent 70010ce691
commit 33bfa908d2
1 changed files with 11 additions and 5 deletions

View File

@ -24,11 +24,17 @@ type Decoder struct {
func (d *Decoder) Decode(v interface{}) (err error) {
defer func() {
if e := recover(); e != nil {
if _, ok := e.(runtime.Error); ok {
panic(e)
}
err = e.(error)
if err != nil {
return
}
r := recover()
_, ok := r.(runtime.Error)
if ok {
panic(r)
}
err, ok = r.(error)
if !ok && r != nil {
panic(r)
}
}()