[CSHARP-1252] Improve error handling in new 2.0 driver Created: 24/Apr/15  Updated: 16/Jul/15  Resolved: 06/May/15

Status: Closed
Project: C# Driver
Component/s: Error Handling
Affects Version/s: 2.0
Fix Version/s: 2.0.1, 2.1

Type: Improvement Priority: Major - P3
Reporter: Lenny Granovsky Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The 1.* version was able to provide server-side messages on all write operations. The application was able to rely on those. Now all errors are being replaced with exceptions that is a good improvement. But messages in those exceptions are very generic and cannot be used nor by the application, nor for debugging purposes to resolve the issue.

For example unique index violation on the server side produces the MongoBulkWriteException with the following message "A bulk write operation resulted in one or more errors." - no mentioning of index even...

The other example, client side this time. The use of "." in the BsonElement for the field name (like "name.partial") is prohibitive. But trying to use such will result into the EndOfStreamException with generic message as well.

It would be very helpful if exception messages describe what the issue is, not what the decision is being made by the driver; and server-side messages must be preserved as they are helpful.



 Comments   
Comment by Githook User [ 06/May/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1252: write exceptions now have more complete messages.
Branch: v2.0.x
https://github.com/mongodb/mongo-csharp-driver/commit/caeb8a4ae2b3332803f7d783b1c8d83ec5ec06e7

Comment by Githook User [ 06/May/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1252: write exceptions now have more complete messages.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/d07349cdfdf0bcba71524b9a535cc448e56cec4a

Comment by Lenny Granovsky [ 24/Apr/15 ]

I think it is perfectly appropriate solution.

Thank you.

Comment by Craig Wilson [ 24/Apr/15 ]

Each WriteError has a category in them that indicates things like DuplicateKey, or ExecutionTimeout. It doesn't make sense for use to try and blow that out into all kinds of different exceptions that will, overtime, get difficult. C#6's exception filters will allow you to inspect this even easier (or if you are using VB, you can already do it). In addition, it would mean you couldn't use the same logic to handle bulk write errors as single write errors.

However, the EndOfStreamException is problematic, so we'll definitely get that fixed.

Craig

Comment by Lenny Granovsky [ 24/Apr/15 ]

I definitely see your point. I think making its own messages for most common cases like duplicate key/index, etc. making more sense. For the index it can simply say "A write operation resulted in a duplicate key error." And then as you mentioned, if we need more details on what index is violated, etc., we can go into WriteErrors collection.

As for the EndOfStreamException, it should simply give the actual error that has been determined.

Thank you for quick response.

Comment by Craig Wilson [ 24/Apr/15 ]

Hi Lenny,

Thanks for the report. While the message itself might not give all the errors, they are all available in the WriteErrors property for you to handle however you'd like. (https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver/MongoBulkWriteException.cs#L76). Are you asking that we take these and put them in the string? This could be extremely long as a large number of errors could potentially occur, so we'd have to cap it at some length regardless and you'd need to handle the WriteErrors property anyways.

The EndOfStreamException certainly is annoying. I'll try and figure out how to make that a better message.

Craig

Generated at Wed Feb 07 21:39:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.