go-plist icon indicating copy to clipboard operation
go-plist copied to clipboard

unmarshal into map with int keys results in panic

Open rogpeppe opened this issue 6 years ago • 1 comments

Unmarshaling into a map with int keys will result in a panic. Although this key type is expressly forbidden, it would be more friendly to return an error in this case, or at least produce a panic message that's clearer than this:

panic: reflect.Value.Convert: value of type string cannot be converted to type int [recovered]
	panic: interface conversion: string is not error: missing method Error

Example code:

https://play.golang.org/p/Qd8TRd2C0LV

rogpeppe avatar Aug 10 '19 16:08 rogpeppe

Is this error message descriptive enough, or should it be more specific?

=== RUN   TestInvalidMapUnmarshal
--- PASS: TestInvalidMapUnmarshal (0.00s)
    unmarshal_test.go:59: Error:  plist: type mismatch: tried to decode plist type `dictionary'
      into value of type `map[int]string'

DHowett avatar Aug 24 '19 17:08 DHowett