Fix panic in ExtractIntoStructPtr
Passing nil as an argument to 'ExtractIntoStructPtr' causes "panic: runtime error: invalid memory address or nil pointer dereference". This is an invalid argument and should be corrected to return an error. For reference, standard package functions such as 'json.Unmarshal' return an error instead of panic.
Fixes #2872
coverage: 77.875% (+0.04%) from 77.832% when pulling 571d3f585aa2baa39408ec51e9274940d00e8596 on bobuhiro11:fix_extract into d0c1d7e079aced9455238c7148da2ca6555d1ac5 on gophercloud:master.
The comment to the function you are modifying specifically mentions that it's "for internal use only". However I realise that since it's exported, it's integral part of the API surface.
I think your change request has merit and it's correctly written. Can you please do the same for ExtractIntoSlicePtr just below?
I have a last-minute doubt about this PR. see https://github.com/gophercloud/gophercloud/issues/2872#issuecomment-1900099365
@pierreprinetti @kayrus Thanks for your review!
I think your change request has merit and it's correctly written. Can you please do the same for ExtractIntoSlicePtr just below?
Of course. I added the same change for ExtractIntoSlicePtr.
thanks for the PR. I think it's also worth adding a check, whether interface is not a pointer. And an error message should be more specific, this should help during the development.
I appied your suggestions.
reflect.ValueOf(to).IsNil() was needed for err5.
@pierreprinetti @kayrus Could you please take a look at it again?
@kayrus are you fine with the changes you requested?