globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

invalid objectid: add field name and real value as message #299

Closed isayme closed 5 years ago

isayme commented 5 years ago

when insert/update an objectid filed, if invalid id passed, the error message will be: ObjectIDs must be exactly 12 bytes long (got 0).

the error message cannot help developer to fingure out the field name.

domodwyer commented 5 years ago

Hi @isayme

I'm not sure this is a good idea, as the values are not necessarily printable strings so users might wind up with random control characters in their output - thanks for the PR though!

Dom

isayme commented 5 years ago

Hi @domodwyer Thanks for your opinion.

What I want to solve is telling developer the exactly field when bson.Marshal, while current error message cannot do that. image

DonovanCharpin commented 4 years ago

I agree, this is maybe one of the most annoying error when we have complex structs with nested structs containing objectIds ... Thanks for the PR, I was able to find the message easily and debug the name of my field