Uploaded image for project: 'Mesos'
  1. Mesos
  2. MESOS-7410

Make it harder to ignore errors returned from functions.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • stout

    Description

      Mesos (or more specifically stout) uses a number of types which can capture either a value or an error (e.g., Try or Result). These are used similar to exceptions, but in contrast to exceptions, the possible errors are part of the function's types. It is also possible to (implicitly) ignore errors return from functions producing such values (this is not possible with exceptions).

      C++11 introduced a generalized syntax for attributes which makes it possible to add attributes to types. C++17 standardized an attribute nodiscard which

      Appears in a function declaration, enumeration declaration, or class declaration. If a function declared nodiscard or a function returning an enumeration or class declared nodiscard by value is called from a discarded-value expression other than a cast to void, the compiler is encouraged to issue a warning.

      With that it is possible to annotate types with a nodiscard attribute which was not possible with e.g., GNU attributes, e.g.,

      class [[nodiscard]] Try;
      

      We should annotate our error types with nodiscard to make sure errors are not missed.

      This will likely require updating call sites to handle currently ignored return values (this appears more widespread in users of e.g., os::close or os::sleep). Since compilers might emit errors for unknown attributes we should also prevent breaking a build on compilers not supporting this attribute.

      Attachments

        Activity

          People

            Unassigned Unassigned
            bbannier Benjamin Bannier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: