-
Notifications
You must be signed in to change notification settings - Fork 532
RUBY-2525 Expose the Reason an Operation Fails Document Validation #2379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/mongo/error/operation_failure.rb
Outdated
# For WriteErrors this is `document['writeErrors'][0]['errInfo']`. | ||
# For all other errors this is nil. | ||
# | ||
# @since 2.11.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer use @since
tags and this one isn't accurate, since the functionality will be added in 2.18. You can remove this @since
tag and, if others are in your way going forward, feel free to get rid of them also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
it 'succeeds and prints the error' do | ||
begin | ||
collection.insert_one({x: 1}) | ||
rescue Mongo::Error => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be Mongo::Error::OperationFailure
, given the else
branch below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@comandeo ready for you
I decided to add a details property to the
OperationFailure
class to better conform with the crud spec.This attribute is defined as follows:
document['writeConcernError']['errInfo']
.document['writeErrors'][0]['errInfo']
.nil
.Now, this makes a lot of sense for the OperationFailure class, but for BulkWriteError it doesn't quite make sense. The problem is that BulkWriteError can have multiple writeErrors inside it. This is troublesome because I'm not sure what to do with the
details
now. Should it be a list of theerrInfo
s of eachwriteError
? This didn't seem to make sense, so I just left the details off theBulkWriteError
class. If the user wants to find that information, they can get there from theresults
attr_reader
.Evergreen Patch