Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert error_result into a proper error code #386

Open
nfrechette opened this issue Dec 21, 2021 · 1 comment
Open

Convert error_result into a proper error code #386

nfrechette opened this issue Dec 21, 2021 · 1 comment

Comments

@nfrechette
Copy link
Owner

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 nfrechette added this to the v3.0 milestone Dec 21, 2021
@nfrechette
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant