bencode: Return ErrUnexpectedEOF instead of EOF in the middle of values
This commit is contained in:
parent
32097526fc
commit
071ade67ae
@ -37,14 +37,21 @@ func (d *Decoder) Decode(v interface{}) (err error) {
|
||||
return
|
||||
}
|
||||
r := recover()
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
_, ok := r.(runtime.Error)
|
||||
if ok {
|
||||
panic(r)
|
||||
}
|
||||
err, ok = r.(error)
|
||||
if !ok && r != nil {
|
||||
if err, ok = r.(error); !ok {
|
||||
panic(r)
|
||||
}
|
||||
// Errors thrown from deeper in parsing are unexpected. At value boundaries, errors should
|
||||
// be returned directly (at least until all the panic nonsense is removed entirely).
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
}()
|
||||
|
||||
pv := reflect.ValueOf(v)
|
||||
@ -566,7 +573,7 @@ func (d *Decoder) parseValue(v reflect.Value) (bool, error) {
|
||||
|
||||
b, err := d.r.ReadByte()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return false, err
|
||||
}
|
||||
d.Offset++
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user