Adjust result.h error condition behavior#128
Conversation
|
|
||
| #pragma once | ||
|
|
||
| // TODO (AEG) This include (cassert) leaked into downstream cpp examples, removing it here breaks builds. |
There was a problem hiding this comment.
dang nice find, are you planning on doing this as a part of this work? If not, consider making a ticket to track
There was a problem hiding this comment.
I think I'm going to update examples first, then adjust that in this PR, that way there's not 3 total PRs
xianshijing-lk
left a comment
There was a problem hiding this comment.
One question, lgtm in general
| /// Move the success value out. | ||
| /// | ||
| /// @throws std::logic_error if `ok() == false`. | ||
| const T&& value() const&& { |
There was a problem hiding this comment.
Question:
do we such overload ? any existing use case ?
I wonder if we should just remove the const T&& / const E&& overloads since they do not bring much practical benefit
There was a problem hiding this comment.
@stephen-derosa any insight here? I agree not a ton of value for such a small data structure. Gonna assume this was agentic thorough-ness and not intentional
There was a problem hiding this comment.
this was agentic as future proofing -- but i agree i think its over-engineered
This PR addresses a minor API change around
result.h(droppingnoexceptlabel)Context:
Resultaccessors were previously markednoexceptclang-tidyflagged this as inaccurate becausestd::geton astd::variantcan throw astd::bad_variant_accessif the type being accessed doesn't match the positionConsidered alternatvies:
noexceptbut using something likestd::get_if(doesn't throw) --> declined due to dereferencingnullptrto maintain API signaturestd::variantentirely to avoid to avoid this issue --> declined because it still doesn't address the root issue, which is accessing an error result on success and vice-versastd::optionalfor accessors --> declined as too impactful to API, and conditionalsok()andhas_error()already exist, would be redundantDecision:
result.haccessor methods dropnoexceptstd::get(users can't do much with a genericstd::bad_variant_accessexception with no message)Impact:
This only affects users of
result.hthat were expecting an exception-free experience, which is negligible if not completely nonexistent at this point in the SDK maturity. In the existing version before this PR, the exception would still actually be thrown if the wrong type was accessed, even though it was markednoexcept.Testing