-
Notifications
You must be signed in to change notification settings - Fork 548
v1::exception and v1::server_error (CXX-3237, CXX-3238) #1501
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
Open
eramongodb
wants to merge
9
commits into
mongodb:master
Choose a base branch
from
eramongodb:cxx-abi-v1-exceptions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,033
−12
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kevinAlbs
approved these changes
Nov 19, 2025
Collaborator
kevinAlbs
left a comment
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.
LGTM. I left minor test comments and a question.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves CXX-3237 and CXX-3238 for the
v1::exceptionandv1::server_errorcomponents.As described in #1482 and prior PRs, rather than exposing error categories in the v1 API, the
mongocxx::v1::source_errcerror condition is used to describe the origin of error codes. See the "throw_exception" test case inmongocxx/test/v1/exception.cppfor reference. On the off-chance that a bson library error code is returned by the mongoc API, its code is stored in the error message ("bson error code <code>: <message>") and converted into aMONGOC_ERROR_BSON_INVALIDerror code instead. (Note:bsoncxx::v1exceptions are not converted.)There is the possibility that the mongoc API returns a SASL library error code. This is probably both unlikely and not intentional given how the
_mongoc_cyrus_is_failurefunction is implemented (mongoc should do its best to convert the SASL error code into a mongoc error code). Nevertheless, if it does manage to be returned by the mongoc API, it is converted into a (undocumented)sasl_error_categoryerror code for diagnosis. When an error category has a dedicated error code type,std::error_code::message(v)formats the error code message using that type, e.g."mongoc_error_code_t:<code>". Otherwise, the message is formatted as"<source> error code <code>", e.g."server error code 12345".The
v1::exception::internal::throw_exception()overloads are the primary method by which most errors returned by mongoc will be converted intomongocxx::v1exceptions. These overloads are comparable tov_noabi::throw_exception<exception_type>()inmongocxx/mongoc_error.hh; unlike the v_noabi overloads, the v1 overloads determine the exception class to throw according to the provided arguments. This is the primary means by which CXX-834 will be addressed going forward, e.g. if we decide to implement the write-related error classes from the CRUD specification, thethrow_exception()function may be extended to select the appropriate write error class to throw according to the fields present in the error document.