bencode: Improve UnmarshalTypeError string and list parsing error context
Helps with #297.
This commit is contained in:
parent
53be473486
commit
d4584c2ca6
|
@ -46,8 +46,7 @@ type UnmarshalTypeError struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *UnmarshalTypeError) Error() string {
|
func (e *UnmarshalTypeError) Error() string {
|
||||||
return "bencode: value (" + e.Value + ") is not appropriate for type: " +
|
return fmt.Sprintf("cannot unmarshal a bencode %s into a %s", e.Value, e.Type)
|
||||||
e.Type.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshaler tried to write to an unexported (therefore unwritable) field.
|
// Unmarshaler tried to write to an unexported (therefore unwritable) field.
|
||||||
|
|
|
@ -346,10 +346,10 @@ func (d *Decoder) parseList(v reflect.Value) error {
|
||||||
switch v.Kind() {
|
switch v.Kind() {
|
||||||
case reflect.Array, reflect.Slice:
|
case reflect.Array, reflect.Slice:
|
||||||
default:
|
default:
|
||||||
panic(&UnmarshalTypeError{
|
return &UnmarshalTypeError{
|
||||||
Value: "array",
|
Value: "list",
|
||||||
Type: v.Type(),
|
Type: v.Type(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
|
|
Loading…
Reference in New Issue