[SERVER-19720] add a std::error_category for MongoDB error codes Created: 03/Aug/15 Updated: 19/Sep/15 Resolved: 13/Aug/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Code |
| Affects Version/s: | None |
| Fix Version/s: | 3.1.7 |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Adam Midvidy | Assignee: | Adam Midvidy |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Sprint: | Platform 8 08/28/15 |
| Participants: |
| Description |
|
In NetworkInterfaceASIO, we often need to indicate error conditions by returning an instance of std::error_code. As we have our own error code space (the codes defined in error_codes.err), we should have our own error category so that we don't collide with any system codes. We will probably also need to generate the code from error_codes.err so that we can convert the codes to their associated strings. |
| Comments |
| Comment by Githook User [ 14/Aug/15 ] | |||
|
Author: {u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}Message: | |||
| Comment by Githook User [ 13/Aug/15 ] | |||
|
Author: {u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}Message: | |||
| Comment by Githook User [ 13/Aug/15 ] | |||
|
Author: {u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}Message: | |||
| Comment by Githook User [ 13/Aug/15 ] | |||
|
Author: {u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}Message: | |||
| Comment by Githook User [ 13/Aug/15 ] | |||
|
Author: {u'username': u'amidvidy', u'name': u'Adam Midvidy', u'email': u'amidvidy@gmail.com'}Message: | |||
| Comment by Adam Midvidy [ 04/Aug/15 ] | |||
|
Yeah, you're right that we don't need code generation. However, the <system_error> API added in C++11 is actually a bit complex. Note that the STL provides both std::error_code and std::error_condition, which represent platform specific and platform independent errors, respectively. Since our ErrorCodes are platform independent, we really should be using std::error_condition, but we need to be able to create instances of std::error_code as well to interoperate with ASIO. As such, there are a few things I think we need to do: 1) Add an implementation of mongo_error_category that extends std::error_category. As you noted, most of the virtual functions we need to implement can be implemented using the existing logic in ErrorCodes. 2) Add an overload of make_error_code for ErrorCodes::Error. 3) Add an overload of make_error_condition for ErrorCodes::Error 4) specialize is_error_code_enum for ErrorCodes::Error 5) specialize is_error_condition_enum for ErrorCodes::Error For reference, here are two blog posts by the author of ASIO, who played a major role in designing the <system_error> API for C++11: | |||
| Comment by Andy Schwerin [ 03/Aug/15 ] | |||
|
Given an error_code with appropriate category, err, I believe we can write ErrorCodes::errorString(static_cast<ErrorCodes::Error>(err.value())). I don't think it needs to be auto-generated. A handful of functions, possibly in status.h, seem appropriate:
|