Skip to content

GH-46791: [C++] Add Status::OrElse, IntoStatus<T> and ToStatus - #46792

Merged
pitrou merged 1 commit into
apache:mainfrom
pitrou:status-or-else
Jun 30, 2025
Merged

GH-46791: [C++] Add Status::OrElse, IntoStatus<T> and ToStatus#46792
pitrou merged 1 commit into
apache:mainfrom
pitrou:status-or-else

Conversation

@pitrou

@pitroupitrou commented Jun 12, 2025

Copy link
Copy Markdown
Member

Rationale for this change

In #46711 (comment) 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?

  1. Add a type trait IntoStatus<T> that can be implemented to provide conversions from other error-like types
  2. Add a global ToStatus function that calls the aforementioned type trait
  3. Add a Status::OrElse method that calls a functor on error
  4. Remove the RETURN_NOT_OK_ELSE macro

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-actions

Copy link
Copy Markdown

⚠️ GitHub issue #46791has been automatically assigned in GitHub to PR creator.

@pitrou

Copy link
Copy Markdown
MemberAuthor

@zanmato1984@bkietz@paleolimbot What do you think?

@pitrou

Copy link
Copy Markdown
MemberAuthor

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()); }));
^

@pitrou
pitrouforce-pushed the status-or-else branch 3 times, most recently from 1c2266a to e2cd325CompareJune 12, 2025 10:43
@pitrou
pitrou marked this pull request as ready for review June 12, 2025 11:29

@paleolimbotpaleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seems reasonable to me! The behaviour seems to line up exactly with Rust's .or_else() and I agree the macro was difficult to understand. The general maintenance around status handling is also great!

Comment threadcpp/src/arrow/status.h Outdated
@github-actionsgithub-actionsBot added awaiting review Awaiting review awaiting merge Awaiting merge and removed awaiting review Awaiting review labels Jun 12, 2025
@pitrou

Copy link
Copy Markdown
MemberAuthor

The behaviour seems to line up exactly with Rust's .or_else()

You can guess it's intended :)

@zanmato1984zanmato1984 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice! A few nits.

Comment threadcpp/src/arrow/status.h Outdated
Comment threadcpp/src/arrow/status.h Outdated
@github-actionsgithub-actionsBot added awaiting review Awaiting review awaiting committer review Awaiting committer review and removed awaiting review Awaiting review awaiting merge Awaiting merge labels Jun 13, 2025

@bkietzbkietz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some nits and an idea for an alternate approach

Comment threadcpp/src/arrow/status.h Outdated
Comment threadcpp/src/arrow/status.h Outdated
Comment threadcpp/src/arrow/status.h Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Jun 16, 2025
@AlenkaF
AlenkaF removed their request for review June 24, 2025 07:59
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 26, 2025
@pitroupitrou changed the title GH-46791: [C++] Add Status::OrElseGH-46791: [C++] Add Status::OrElse, IntoStatus<T> and ToStatusJun 26, 2025
@pitrou

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp

@github-actions

This comment was marked as outdated.

@pitrou

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp

@github-actions

Copy link
Copy Markdown

Revision: 65723c8

Submitted crossbow builds: ursacomputing/crossbow @ actions-dcfad22df7

TaskStatus
example-cpp-minimal-build-staticGitHub Actions
example-cpp-minimal-build-static-system-dependencyGitHub Actions
example-cpp-tutorialGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindGitHub Actions
test-cuda-cpp-ubuntu-22.04-cuda-11.7.1GitHub Actions
test-debian-12-cpp-amd64GitHub Actions
test-debian-12-cpp-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-bundledGitHub Actions
test-ubuntu-22.04-cpp-emscriptenGitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-bundled-offlineGitHub Actions
test-ubuntu-24.04-cpp-gcc-13-bundledGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-24.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-24.04-cpp-thread-sanitizerGitHub Actions

@pitrou

Copy link
Copy Markdown
MemberAuthor

@zanmato1984@paleolimbot@bkietz I've tried to address all your comments and suggestions, can you take a look again?

@paleolimbotpaleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement on the ergonomics of working with the Status! I took a look through for anything out of place although some of the C++ metaprogramming is over my head here 🙂

@github-actionsgithub-actionsBot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Jun 28, 2025

@zanmato1984zanmato1984 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pitrou
pitrou merged commit 0140089 into apache:mainJun 30, 2025
@pitroupitrou removed the awaiting merge Awaiting merge label Jun 30, 2025
@pitroupitrou mentioned this pull request Jun 30, 2025
@pitrou
pitrou deleted the status-or-else branch June 30, 2025 07:14
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 0140089.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pitrou@zanmato1984@bkietz@paleolimbot