acl icon indicating copy to clipboard operation
acl copied to clipboard

Convert error_result into a proper error code

Open nfrechette opened this issue 4 years ago • 1 comments

Various functions currently return an error_result with an optional error string. This is readable and nice in the debugger but it is unfortunately not very friendly for a few reasons.

  • Searching the documentation or on google for an error string is more complicated
  • It is not possible to reliable branch on an error result string as it could change during a minor update
  • Handling of errors is awkward
  • It is harder to maintain a translation into non-English languages

Instead, a proper error code similar to Windows error codes should be used. A single typed enum with value ranges reserved for certain things.

Zero init should represent an unknown error. One should represent success. Negative (and zero) values can represent error codes.

A free standing to_string(enum value) function can be introduced to convert error codes to readable strings.

This will represent an API break which is not ideal. As such, we should target 3.0 for a full migration. We could do this earlier by introducing a shim that coerces to the old type and the new type automatically and forwards the few functions calls we currently have to sensible defaults. A deprecation warning could be added.

nfrechette avatar Dec 21 '21 03:12 nfrechette

Consider using std::error_condition: https://en.cppreference.com/w/cpp/error/error_condition See asio C++ for an example

nfrechette avatar Jan 13 '24 16:01 nfrechette