-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Internal Code
-
Fully Compatible
-
ALL
There's sloppy conflation of errno with GetLastError codes, and possibly more error code spaces like asio, ssl.
Win32 has both an errno int (signed 32-bit) and a GetLastError DWORD (unsigned 32-bit). They aren't in the same number space, and a DWORD can't be portably stored into a signed int without special care (which we aren't taking). I correctly get compiler errors from the narrowing conversions of DWORD to int after textually replacing errnoWithDescription(e) expressions to Errno{e}.desc() expressions. Braced-init doesn't tolerate narrowing!
Logically, a function called errnoWithDescription should only be looking at errno codes, but we have it so that it does a GetLastError on Win32, and there is no helper function analyze the `errno` codes (as set by _read, etc) on Win32. We need to keep GetLastError and errno regimes separated to do this right. We'll have clearer and more correct error handling.
C++11's <system_error> introduced std::error_code which separates errors into an {int, category} pair, so these can be kept straight. It also introduces a clear lossless exception type for std::error_code, called std::system_error. What we usually do in mongo code is a kind of punt where we try to uassert to convert any system errors into DBException on the way up.
The system_error API.
https://en.cppreference.com/w/cpp/header/system_error
Discussion of system_error, some problems (you have to be careful with it, so maybe we write wrappers), and forward-looking solutions for it.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0824r1.html
- is related to
-
SERVER-41353 Fix late calls to errnoWithDescription()
- Closed