Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-50253

errno-style handlers conflate error categories

    • 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

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: