[GODRIVER-1005] Decoding SingleResult or cursor to nil pointer type panics Created: 29/Apr/19 Updated: 28/Oct/23 Resolved: 08/May/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | 1.0.1 |
| Fix Version/s: | 1.0.2 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | David Golden | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Description |
|
Decoding to a nil pointer of a type panics. This pattern works:
This pattern panics:
This is subtle and users are likely to mess this up. We should detect this condition and return an instructive error instead of panicking and should document this limitation clearly. We do this for other usage errors, such as "argument to Decode must be a pointer to a type, but got map[]". Sample program:
Output:
|
| Comments |
| Comment by Githook User [ 08/May/19 ] |
|
Author: {'name': 'Divjot Arora', 'username': 'divjotarora', 'email': 'divjot.arora@10gen.com'}Message: Disallow decoding BSON to nil pointer. Change-Id: I52ea2e1c2b200abfae82baa58b6dc954228e9e2a |
| Comment by Githook User [ 08/May/19 ] |
|
Author: {'email': 'divjot.arora@10gen.com', 'name': 'Divjot Arora', 'username': 'divjotarora'}Message: Disallow decoding BSON to nil pointer. Change-Id: I52ea2e1c2b200abfae82baa58b6dc954228e9e2a |
| Comment by Divjot Arora (Inactive) [ 03/May/19 ] |
|
CR: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/452634 |