-
#include "tensorstore/util/status.h" -
TENSORSTORE_RETURN_IF_ERROR(...);
Causes the containing function to return the specified
absl::Statusvalue 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_ERRORmacro implicitly returns atensorstore::StatusBuilderobject which may be used to further modify the status. Atensorstore::StatusBuilderis implicitly convertible to anabsl::Status, however when used in lambdas the return type may need to be explicitly specified asabsl::Status.To explicitly convert to
absl::Statususe.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_ERRORwhere 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 thetensorstore::StatusBuilder. The second argument must be a valid expression for the right-hand side of areturnstatement.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.