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

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

    XMLWordPrintable

    Details

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

      Description

      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;
         }
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: