[GODRIVER-1627] Return structured or configurable error for bson.Unmarshal Created: 26/May/20  Updated: 28/Oct/23  Resolved: 11/Jun/20

Status: Closed
Project: Go Driver
Component/s: Error Handling
Affects Version/s: None
Fix Version/s: 1.4.0

Type: Improvement Priority: Major - P3
Reporter: Daniel Ernst Assignee: Divjot Arora (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends

 Description   

It would be useful for Atlas Data Lake if the errors returned by calls to bson.UnmarshalWithRegistry were structured or configurable so that we could extract certain information that we want to expose to the user (like the tag of the field that errored), and hide our internal implementation details from the user (like the name of the struct that could not be decoded).

For example, as illustrated in MHOUSE-1425: when we decode a user-supplied command, if the command is not structured properly, we'll get an error from bson.UnmarshalWithRegistry like this:

cannot decode document into []internalADLStruct

The trouble is that we don't want to expose our internal struct types, and as a result we have to throw out this whole error message, leaving the user with something generic like "failed to parse command".

So either we'd like to be able to specify that the error message should not include the struct field name. Or even better, it would be great if we got back a structured error that allowed us to manually pull out the tag, struct field name, and given type so that we can craft our own error message.

I don't quite understand the decoding logic well enough to know how big / possible of an ask this is so let me know. It's not mission critical for ADL, but would definitely result in a better experience for our users.



 Comments   
Comment by Githook User [ 11/Jun/20 ]

Author:

{'name': 'Divjot Arora', 'email': 'divjot.arora@10gen.com', 'username': 'divjotarora'}

Message: GODRIVER-1627 Export keys slice from bsoncodec.DecodeError (#421)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/324f6a9484e8978d0126956e281a319e4e7a3d61

Generated at Thu Feb 08 08:36:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.