diff --git a/bencode/api.go b/bencode/api.go index 15687a8c..3e3c1633 100644 --- a/bencode/api.go +++ b/bencode/api.go @@ -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. diff --git a/bencode/decode.go b/bencode/decode.go index 03488999..13e63f71 100644 --- a/bencode/decode.go +++ b/bencode/decode.go @@ -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