-
#include "tensorstore/util/status_builder.h" - class [[warn_unused_result]] tensorstore::StatusBuilder;
StatusBuilderis a builder object for constructingabsl::Statusobjects, with methods to override the status code, augment the error message, and attach payloads.A
StatusBuilderis implicitly convertible toabsl::Status, and theabsl::Statuscan be explicitly constructed using the methodStatusBuilder::BuildStatus().Example:
absl::Status foo(int i) { if (i < 0) { return StatusBuilder(absl::StatusCode::kInvalidArgument) .Format("i=%d", i); } return absl::OkStatus(); }StatusBuilderis primarily used in theTENSORSTORE_RETURN_IF_ERRORandTENSORSTORE_ASSIGN_OR_RETURNmacros.Constructors¶
-
explicit StatusBuilder(
absl::Status status,
std::source_location loc = std::source_location::current()); Creates a
StatusBuilderfrom an existing status. If thestatusis notabsl::StatusCode::kOk, the source location may be added to it.
-
explicit StatusBuilder(
absl::StatusCode code,
std::source_location loc = std::source_location::current()); Creates a
StatusBuilderwith the given statuscodeand an empty message.
Methods¶
- bool ok() const;
Returns whether the current status code is
absl::StatusCode::kOk.
- absl::StatusCode code() const;
Returns the status code of the underlying status, or the overridden code if one has been set.
- StatusBuilder& SetCode(absl::StatusCode code) &;
- StatusBuilder&& SetCode(absl::StatusCode code) &&;
Overrides the absl::StatusCode on the error.
codemust not beabsl::StatusCode::kOk.
-
StatusBuilder&
Format(const absl::FormatSpec<Args...>& format, const Args&... args); Adds a formatted message to the status.
- StatusBuilder& SetPrepend();
Mutates the builder so that any formatted message is prepended to the status.
- StatusBuilder& SetAppend();
Mutates the builder so that any formatted message is appended to the status.
- std::optional<absl::Cord> GetPayload(std::string_view type_url) const;
Returns payload for the given type URL, or nullopt if not found.
-
StatusBuilder&
SetPayload(std::string_view type_url, absl::Cord payload); -
StatusBuilder&
SetPayload(std::string_view type_url, std::string_view payload); - StatusBuilder& SetPayload(std::string_view type_url, T&& payload);
Sets a payload on the status equivalent to
absl::Status::SetPayload.
-
StatusBuilder&
AddStatusPayload(std::string_view type_url, absl::Cord payload); Adds a payload value to status.
-
auto With(Adaptor&& adaptor) & -> decltype(std::forward<Adaptor>(
adaptor)(*this)); -
auto With(Adaptor&& adaptor) && -> decltype(std::forward<Adaptor>(
adaptor)(std::move(*this))); Applies a custom
adaptorfunctor to the StatusBuilder.
- __attribute__((warn_unused_result)) absl::Status BuildStatus() const&;
- __attribute__((warn_unused_result)) absl::Status BuildStatus() &&;
Constructs an
absl::Statusfrom the current state.
Conversion operators¶
- operator absl::Status() const&;
- operator absl::Status() &&;
Converts to
absl::Status.
-
explicit StatusBuilder(
Related Functions¶
- absl::Status tensorstore::GetStatus(StatusBuilder&& status_builder);
-
absl::Status
tensorstore::GetStatus(const StatusBuilder& status_builder); Returns the
absl::Statusfor the StatusBuilder.