GH-46791: [C++] Add `Status::OrElse`
Rationale for this change
In https://github.com/apache/arrow/pull/46711#discussion_r2139246309 it was mentioned that the macro RETURN_NOT_OK_ELSE is confusing and can easily be misunderstood. We would like a better way to conditionally chain error-handling code if a Status does not indicate success.
What changes are included in this PR?
- Add a global
ToArrowStatusfunction to allow registering third-party conversions toStatus - Add a
Status::OrElsemethod that calls a functor on error - Remove the
RETURN_NOT_OK_ELSEmacro
Are these changes tested?
Yes.
Are there any user-facing changes?
No, the RETURN_NOT_OK_ELSE was not supposed to be called by third-party code as it's not prefixed with ARROW_.
- GitHub Issue: #46791
:warning: GitHub issue #46791 has been automatically assigned in GitHub to PR creator.
@zanmato1984 @bkietz @paleolimbot What do you think?
Ah, clang is being picky.
/Users/runner/work/arrow/arrow/cpp/src/arrow/status.h:363:16: error: cannot pass object of non-trivial type 'arrow::Status' through variadic method; call will abort at runtime [-Wnon-pod-varargs]
on_error(*this);
^
/Users/runner/work/arrow/arrow/cpp/src/parquet/arrow/writer.cc:392:31: note: in instantiation of function template specialization 'arrow::Status::OrElse<(lambda at /Users/runner/work/arrow/arrow/cpp/src/parquet/arrow/writer.cc:391:7)>' requested here
WriteRowGroup(0, 0).OrElse([&](...) { PARQUET_IGNORE_NOT_OK(Close()); }));
^
The behaviour seems to line up exactly with Rust's
.or_else()
You can guess it's intended :)
@github-actions crossbow submit -g cpp
Revision: 7a16cd01469da210e59984180231501683a76910
Submitted crossbow builds: ursacomputing/crossbow @ actions-500c512008
@github-actions crossbow submit -g cpp
Revision: 65723c88fbc84c38cbfbde95a029c97209234a90
Submitted crossbow builds: ursacomputing/crossbow @ actions-dcfad22df7
@zanmato1984 @paleolimbot @bkietz I've tried to address all your comments and suggestions, can you take a look again?
After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 0140089a7fab24a1e886a86b659047cf51471e6c.
There were no benchmark performance regressions. 🎉
The full Conbench report has more details.