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 {
|
||||
return "bencode: value (" + e.Value + ") is not appropriate for type: " +
|
||||
e.Type.String()
|
||||
return fmt.Sprintf("cannot unmarshal a bencode %s into a %s", e.Value, e.Type)
|
||||
}
|
||||
|
||||
// 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() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
default:
|
||||
panic(&UnmarshalTypeError{
|
||||
Value: "array",
|
||||
return &UnmarshalTypeError{
|
||||
Value: "list",
|
||||
Type: v.Type(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
i := 0
|
||||
|
|
Loading…
Reference in New Issue