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

Error Helpers #43

Open
EvanLF6768 opened this issue Jun 2, 2024 · 0 comments
Open

Error Helpers #43

EvanLF6768 opened this issue Jun 2, 2024 · 0 comments

Comments

@EvanLF6768
Copy link
Contributor

Common operations and interfaces should have a well defined way in which they can fail (likely using std::expected). It should be possible to propagate errors up through functions with some sort of compound error object (combination of context and inner) in a concise manner. For example:

enum class WangleError {
    kCantGetFoo,
    kWanglingByZero,
};
auto Wangle() -> std::expected<int, obc::error::Error<
    obc::error::Case<WangleError::kCantGetFoo, decltype(GetFoo())::error_type>,
    obc::error::Case<WangleError::kWanglingByZero>
>> {
    auto foo = GetFoo();
    if (!foo) return obc::error::Fail(WangleError::kCantGetFoo, foo);
    // Use the value of foo
}

bugprone-unchecked-optional-access must be expanded to work with std::expected.

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

No branches or pull requests

1 participant