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

mongo::Status implicit conversion to mongo::ErrorCodes::Error

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Build
    • Labels:
      None

      If we add a conversion member to Status, we can use the idiom

         switch (auto status = fun()) {
              case ErrorCodes::Error::NoSuchKey: break;
              default: return status;
         }
      

      For this to be safe, we would need to change Error to an "enum class". Otherwise, the implicit promotion ErrorCodes::Error -> int would allow a Status to be passed to a function taking int. That change would, in turn, require changing mentions of "ErrorCodes::<name>" to "ErrorCodes::Error::<name>", as seen above.

      Alternatively, the type Error could be eliminated, and the enumerators promoted to an enum class ErrorCodes. That would require changing the ErrorCodes static members to namespace-scoped functions.

      Or, the enum type Error could be left with no enumerators, but instead define constexpr values in ErrorCodes. That would not require changes in most uses of ErrorCodes, and the idiom would look like

         switch (auto status = fun()) {
              case ErrorCodes::NoSuchKey: break;
              default: return status;
         }
      

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            nathan.myers Nathan Myers
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: