#include "tensorstore/util/status.h"
TENSORSTORE_RETURN_IF_ERROR(...);

Causes the containing function to return the specified absl::Status value if it is an error status.

Example:

absl::Status GetSomeStatus();

absl::Status Bar() {
  TENSORSTORE_RETURN_IF_ERROR(GetSomeStatus());
  // More code
  return absl::OkStatus();
}

The TENSORSTORE_RETURN_IF_ERROR macro implicitly returns a tensorstore::StatusBuilder object which may be used to further modify the status. A tensorstore::StatusBuilder is implicitly convertible to an absl::Status, however when used in lambdas the return type may need to be explicitly specified as absl::Status.

To explicitly convert to absl::Status use .BuildStatus(), or use the .With() method return a different type (including void).

Example:

TENSORSTORE_RETURN_IF_ERROR(GetSomeStatus())
    .Format("In Bar");

TENSORSTORE_RETURN_IF_ERROR(GetSomeStatus())
    .Format("In Bar")
    .With([&](absl::Status s) { future.SetResult(std::move(s)); });

auto my_lambda = []() -> absl::Status {
  TENSORSTORE_RETURN_IF_ERROR(GetSomeStatus());
  return absl::OkStatus();
};

There is also a 2-argument form of TENSORSTORE_RETURN_IF_ERROR where the second argument is an error expression which is evaluated only if the first argument is an error. When invoked with two arguments, _ is bound to the tensorstore::StatusBuilder. The second argument must be a valid expression for the right-hand side of a return statement.

Example:

TENSORSTORE_RETURN_IF_ERROR(GetSomeStatus(),
                            _.Format("In Bar"));

Warning

The first argument must not contain any commas outside parentheses (such as in a template argument list); if necessary, to ensure this, it may be wrapped in additional parentheses as needed.