[CXX-2120] Handling of nonexistent document fields is frustrating Created: 15/Oct/20 Updated: 28/Oct/23 Resolved: 30/Jun/23 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 3.9.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Samantha Ritter (Inactive) | Assignee: | Josh Siegel (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | rb-track | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Epic Link: | CXX usability improvements |
| Quarter: | FY24Q2 |
| Description |
|
Consider a document doc = { "secret" : "message" }. If I attempt to access a non-existent field doc["sceret"], either because I made a typo in my code or for another reason, then use the resulting document::element, the driver throws a vague and unhelpful exception. The root problem here is that the code that throws the exception runs when I attempt to use the result of my field lookup, not when I perform the lookup itself:
Once my unset element e is created, it loses any attachment to my original query (with the problematic nonexistent typo field "sceret"). This makes it very hard to improve the user experience with nonexistent fields. It makes it impossible for us to provide a more helpful exception message (like "document field 'sceret' does not exist"). The most common use case probably looks like this, with method chaining after the field lookup:
Exception stack tracing could help in this use case, because the line with the offending lookup would be included in the trace. However, the exception will still have been thrown from a different place, in the get_string() method, which could be confusing for users. document's operator[] used to throw, but several tickets removed that behavior: Those tickets discuss their reasons for removing throwing from operator[], which include wanting to remove inconsistencies between different classes in the driver. However, we should revisit these discussions and decide whether those arguments outweigh the sheer frustration of debugging typos in document lookup, and how that plays into the overall frustration users experience with the driver. |
| Comments |
| Comment by Githook User [ 30/Jun/23 ] | |||
|
Author: {'name': 'Joshua Siegel', 'email': '39130209+joshbsiegel@users.noreply.github.com', 'username': 'joshbsiegel'}Message: | |||
| Comment by Kevin Albertson [ 19/Oct/20 ] | |||
|
We can reopen the discussion on this. Another advantage of not throwing on non-existent field lookup is having a convenient way of checking for existence:
|