diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/restricted/abseil-cpp-tstring/y_absl/status/status.cc | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/restricted/abseil-cpp-tstring/y_absl/status/status.cc')
-rw-r--r-- | contrib/restricted/abseil-cpp-tstring/y_absl/status/status.cc | 826 |
1 files changed, 413 insertions, 413 deletions
diff --git a/contrib/restricted/abseil-cpp-tstring/y_absl/status/status.cc b/contrib/restricted/abseil-cpp-tstring/y_absl/status/status.cc index 3b7fe28e08..9884ab8060 100644 --- a/contrib/restricted/abseil-cpp-tstring/y_absl/status/status.cc +++ b/contrib/restricted/abseil-cpp-tstring/y_absl/status/status.cc @@ -1,292 +1,292 @@ -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#include "y_absl/status/status.h" - -#include <cassert> - -#include "y_absl/base/internal/raw_logging.h" -#include "y_absl/debugging/stacktrace.h" -#include "y_absl/debugging/symbolize.h" -#include "y_absl/status/status_payload_printer.h" -#include "y_absl/strings/escaping.h" -#include "y_absl/strings/str_cat.h" -#include "y_absl/strings/str_format.h" -#include "y_absl/strings/str_split.h" - -namespace y_absl { -ABSL_NAMESPACE_BEGIN - -TString StatusCodeToString(StatusCode code) { - switch (code) { - case StatusCode::kOk: - return "OK"; - case StatusCode::kCancelled: - return "CANCELLED"; - case StatusCode::kUnknown: - return "UNKNOWN"; - case StatusCode::kInvalidArgument: - return "INVALID_ARGUMENT"; - case StatusCode::kDeadlineExceeded: - return "DEADLINE_EXCEEDED"; - case StatusCode::kNotFound: - return "NOT_FOUND"; - case StatusCode::kAlreadyExists: - return "ALREADY_EXISTS"; - case StatusCode::kPermissionDenied: - return "PERMISSION_DENIED"; - case StatusCode::kUnauthenticated: - return "UNAUTHENTICATED"; - case StatusCode::kResourceExhausted: - return "RESOURCE_EXHAUSTED"; - case StatusCode::kFailedPrecondition: - return "FAILED_PRECONDITION"; - case StatusCode::kAborted: - return "ABORTED"; - case StatusCode::kOutOfRange: - return "OUT_OF_RANGE"; - case StatusCode::kUnimplemented: - return "UNIMPLEMENTED"; - case StatusCode::kInternal: - return "INTERNAL"; - case StatusCode::kUnavailable: - return "UNAVAILABLE"; - case StatusCode::kDataLoss: - return "DATA_LOSS"; - default: - return ""; - } -} - -std::ostream& operator<<(std::ostream& os, StatusCode code) { - return os << StatusCodeToString(code); -} - -namespace status_internal { - -static int FindPayloadIndexByUrl(const Payloads* payloads, - y_absl::string_view type_url) { - if (payloads == nullptr) return -1; - +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "y_absl/status/status.h" + +#include <cassert> + +#include "y_absl/base/internal/raw_logging.h" +#include "y_absl/debugging/stacktrace.h" +#include "y_absl/debugging/symbolize.h" +#include "y_absl/status/status_payload_printer.h" +#include "y_absl/strings/escaping.h" +#include "y_absl/strings/str_cat.h" +#include "y_absl/strings/str_format.h" +#include "y_absl/strings/str_split.h" + +namespace y_absl { +ABSL_NAMESPACE_BEGIN + +TString StatusCodeToString(StatusCode code) { + switch (code) { + case StatusCode::kOk: + return "OK"; + case StatusCode::kCancelled: + return "CANCELLED"; + case StatusCode::kUnknown: + return "UNKNOWN"; + case StatusCode::kInvalidArgument: + return "INVALID_ARGUMENT"; + case StatusCode::kDeadlineExceeded: + return "DEADLINE_EXCEEDED"; + case StatusCode::kNotFound: + return "NOT_FOUND"; + case StatusCode::kAlreadyExists: + return "ALREADY_EXISTS"; + case StatusCode::kPermissionDenied: + return "PERMISSION_DENIED"; + case StatusCode::kUnauthenticated: + return "UNAUTHENTICATED"; + case StatusCode::kResourceExhausted: + return "RESOURCE_EXHAUSTED"; + case StatusCode::kFailedPrecondition: + return "FAILED_PRECONDITION"; + case StatusCode::kAborted: + return "ABORTED"; + case StatusCode::kOutOfRange: + return "OUT_OF_RANGE"; + case StatusCode::kUnimplemented: + return "UNIMPLEMENTED"; + case StatusCode::kInternal: + return "INTERNAL"; + case StatusCode::kUnavailable: + return "UNAVAILABLE"; + case StatusCode::kDataLoss: + return "DATA_LOSS"; + default: + return ""; + } +} + +std::ostream& operator<<(std::ostream& os, StatusCode code) { + return os << StatusCodeToString(code); +} + +namespace status_internal { + +static int FindPayloadIndexByUrl(const Payloads* payloads, + y_absl::string_view type_url) { + if (payloads == nullptr) return -1; + for (size_t i = 0; i < payloads->size(); ++i) { - if ((*payloads)[i].type_url == type_url) return i; - } - - return -1; -} - -// Convert canonical code to a value known to this binary. -y_absl::StatusCode MapToLocalCode(int value) { - y_absl::StatusCode code = static_cast<y_absl::StatusCode>(value); - switch (code) { - case y_absl::StatusCode::kOk: - case y_absl::StatusCode::kCancelled: - case y_absl::StatusCode::kUnknown: - case y_absl::StatusCode::kInvalidArgument: - case y_absl::StatusCode::kDeadlineExceeded: - case y_absl::StatusCode::kNotFound: - case y_absl::StatusCode::kAlreadyExists: - case y_absl::StatusCode::kPermissionDenied: - case y_absl::StatusCode::kResourceExhausted: - case y_absl::StatusCode::kFailedPrecondition: - case y_absl::StatusCode::kAborted: - case y_absl::StatusCode::kOutOfRange: - case y_absl::StatusCode::kUnimplemented: - case y_absl::StatusCode::kInternal: - case y_absl::StatusCode::kUnavailable: - case y_absl::StatusCode::kDataLoss: - case y_absl::StatusCode::kUnauthenticated: - return code; - default: - return y_absl::StatusCode::kUnknown; - } -} -} // namespace status_internal - -y_absl::optional<y_absl::Cord> Status::GetPayload( - y_absl::string_view type_url) const { - const auto* payloads = GetPayloads(); - int index = status_internal::FindPayloadIndexByUrl(payloads, type_url); - if (index != -1) return (*payloads)[index].payload; - - return y_absl::nullopt; -} - -void Status::SetPayload(y_absl::string_view type_url, y_absl::Cord payload) { - if (ok()) return; - - PrepareToModify(); - - status_internal::StatusRep* rep = RepToPointer(rep_); - if (!rep->payloads) { - rep->payloads = y_absl::make_unique<status_internal::Payloads>(); - } - - int index = - status_internal::FindPayloadIndexByUrl(rep->payloads.get(), type_url); - if (index != -1) { - (*rep->payloads)[index].payload = std::move(payload); - return; - } - - rep->payloads->push_back({TString(type_url), std::move(payload)}); -} - -bool Status::ErasePayload(y_absl::string_view type_url) { - int index = status_internal::FindPayloadIndexByUrl(GetPayloads(), type_url); - if (index != -1) { - PrepareToModify(); - GetPayloads()->erase(GetPayloads()->begin() + index); - if (GetPayloads()->empty() && message().empty()) { - // Special case: If this can be represented inlined, it MUST be - // inlined (EqualsSlow depends on this behavior). - StatusCode c = static_cast<StatusCode>(raw_code()); - Unref(rep_); - rep_ = CodeToInlinedRep(c); - } - return true; - } - - return false; -} - -void Status::ForEachPayload( + if ((*payloads)[i].type_url == type_url) return i; + } + + return -1; +} + +// Convert canonical code to a value known to this binary. +y_absl::StatusCode MapToLocalCode(int value) { + y_absl::StatusCode code = static_cast<y_absl::StatusCode>(value); + switch (code) { + case y_absl::StatusCode::kOk: + case y_absl::StatusCode::kCancelled: + case y_absl::StatusCode::kUnknown: + case y_absl::StatusCode::kInvalidArgument: + case y_absl::StatusCode::kDeadlineExceeded: + case y_absl::StatusCode::kNotFound: + case y_absl::StatusCode::kAlreadyExists: + case y_absl::StatusCode::kPermissionDenied: + case y_absl::StatusCode::kResourceExhausted: + case y_absl::StatusCode::kFailedPrecondition: + case y_absl::StatusCode::kAborted: + case y_absl::StatusCode::kOutOfRange: + case y_absl::StatusCode::kUnimplemented: + case y_absl::StatusCode::kInternal: + case y_absl::StatusCode::kUnavailable: + case y_absl::StatusCode::kDataLoss: + case y_absl::StatusCode::kUnauthenticated: + return code; + default: + return y_absl::StatusCode::kUnknown; + } +} +} // namespace status_internal + +y_absl::optional<y_absl::Cord> Status::GetPayload( + y_absl::string_view type_url) const { + const auto* payloads = GetPayloads(); + int index = status_internal::FindPayloadIndexByUrl(payloads, type_url); + if (index != -1) return (*payloads)[index].payload; + + return y_absl::nullopt; +} + +void Status::SetPayload(y_absl::string_view type_url, y_absl::Cord payload) { + if (ok()) return; + + PrepareToModify(); + + status_internal::StatusRep* rep = RepToPointer(rep_); + if (!rep->payloads) { + rep->payloads = y_absl::make_unique<status_internal::Payloads>(); + } + + int index = + status_internal::FindPayloadIndexByUrl(rep->payloads.get(), type_url); + if (index != -1) { + (*rep->payloads)[index].payload = std::move(payload); + return; + } + + rep->payloads->push_back({TString(type_url), std::move(payload)}); +} + +bool Status::ErasePayload(y_absl::string_view type_url) { + int index = status_internal::FindPayloadIndexByUrl(GetPayloads(), type_url); + if (index != -1) { + PrepareToModify(); + GetPayloads()->erase(GetPayloads()->begin() + index); + if (GetPayloads()->empty() && message().empty()) { + // Special case: If this can be represented inlined, it MUST be + // inlined (EqualsSlow depends on this behavior). + StatusCode c = static_cast<StatusCode>(raw_code()); + Unref(rep_); + rep_ = CodeToInlinedRep(c); + } + return true; + } + + return false; +} + +void Status::ForEachPayload( y_absl::FunctionRef<void(y_absl::string_view, const y_absl::Cord&)> visitor) - const { - if (auto* payloads = GetPayloads()) { - bool in_reverse = - payloads->size() > 1 && reinterpret_cast<uintptr_t>(payloads) % 13 > 6; - + const { + if (auto* payloads = GetPayloads()) { + bool in_reverse = + payloads->size() > 1 && reinterpret_cast<uintptr_t>(payloads) % 13 > 6; + for (size_t index = 0; index < payloads->size(); ++index) { - const auto& elem = - (*payloads)[in_reverse ? payloads->size() - 1 - index : index]; - -#ifdef NDEBUG - visitor(elem.type_url, elem.payload); -#else + const auto& elem = + (*payloads)[in_reverse ? payloads->size() - 1 - index : index]; + +#ifdef NDEBUG + visitor(elem.type_url, elem.payload); +#else // In debug mode invalidate the type url to prevent users from relying on // this string lifetime. - - // NOLINTNEXTLINE intentional extra conversion to force temporary. - visitor(TString(elem.type_url), elem.payload); -#endif // NDEBUG - } - } -} - -const TString* Status::EmptyString() { - static TString* empty_string = new TString(); - return empty_string; -} - -constexpr const char Status::kMovedFromString[]; - -const TString* Status::MovedFromString() { - static TString* moved_from_string = new TString(kMovedFromString); - return moved_from_string; -} - -void Status::UnrefNonInlined(uintptr_t rep) { - status_internal::StatusRep* r = RepToPointer(rep); - // Fast path: if ref==1, there is no need for a RefCountDec (since - // this is the only reference and therefore no other thread is - // allowed to be mucking with r). - if (r->ref.load(std::memory_order_acquire) == 1 || - r->ref.fetch_sub(1, std::memory_order_acq_rel) - 1 == 0) { - delete r; - } -} - -Status::Status(y_absl::StatusCode code, y_absl::string_view msg) - : rep_(CodeToInlinedRep(code)) { - if (code != y_absl::StatusCode::kOk && !msg.empty()) { + + // NOLINTNEXTLINE intentional extra conversion to force temporary. + visitor(TString(elem.type_url), elem.payload); +#endif // NDEBUG + } + } +} + +const TString* Status::EmptyString() { + static TString* empty_string = new TString(); + return empty_string; +} + +constexpr const char Status::kMovedFromString[]; + +const TString* Status::MovedFromString() { + static TString* moved_from_string = new TString(kMovedFromString); + return moved_from_string; +} + +void Status::UnrefNonInlined(uintptr_t rep) { + status_internal::StatusRep* r = RepToPointer(rep); + // Fast path: if ref==1, there is no need for a RefCountDec (since + // this is the only reference and therefore no other thread is + // allowed to be mucking with r). + if (r->ref.load(std::memory_order_acquire) == 1 || + r->ref.fetch_sub(1, std::memory_order_acq_rel) - 1 == 0) { + delete r; + } +} + +Status::Status(y_absl::StatusCode code, y_absl::string_view msg) + : rep_(CodeToInlinedRep(code)) { + if (code != y_absl::StatusCode::kOk && !msg.empty()) { rep_ = PointerToRep(new status_internal::StatusRep(code, msg, nullptr)); - } -} - -int Status::raw_code() const { - if (IsInlined(rep_)) { - return static_cast<int>(InlinedRepToCode(rep_)); - } - status_internal::StatusRep* rep = RepToPointer(rep_); - return static_cast<int>(rep->code); -} - -y_absl::StatusCode Status::code() const { - return status_internal::MapToLocalCode(raw_code()); -} - -void Status::PrepareToModify() { - ABSL_RAW_CHECK(!ok(), "PrepareToModify shouldn't be called on OK status."); - if (IsInlined(rep_)) { + } +} + +int Status::raw_code() const { + if (IsInlined(rep_)) { + return static_cast<int>(InlinedRepToCode(rep_)); + } + status_internal::StatusRep* rep = RepToPointer(rep_); + return static_cast<int>(rep->code); +} + +y_absl::StatusCode Status::code() const { + return status_internal::MapToLocalCode(raw_code()); +} + +void Status::PrepareToModify() { + ABSL_RAW_CHECK(!ok(), "PrepareToModify shouldn't be called on OK status."); + if (IsInlined(rep_)) { rep_ = PointerToRep(new status_internal::StatusRep( static_cast<y_absl::StatusCode>(raw_code()), y_absl::string_view(), nullptr)); - return; - } - - uintptr_t rep_i = rep_; - status_internal::StatusRep* rep = RepToPointer(rep_); - if (rep->ref.load(std::memory_order_acquire) != 1) { - std::unique_ptr<status_internal::Payloads> payloads; - if (rep->payloads) { - payloads = y_absl::make_unique<status_internal::Payloads>(*rep->payloads); - } + return; + } + + uintptr_t rep_i = rep_; + status_internal::StatusRep* rep = RepToPointer(rep_); + if (rep->ref.load(std::memory_order_acquire) != 1) { + std::unique_ptr<status_internal::Payloads> payloads; + if (rep->payloads) { + payloads = y_absl::make_unique<status_internal::Payloads>(*rep->payloads); + } status_internal::StatusRep* const new_rep = new status_internal::StatusRep( rep->code, message(), std::move(payloads)); rep_ = PointerToRep(new_rep); - UnrefNonInlined(rep_i); - } -} - -bool Status::EqualsSlow(const y_absl::Status& a, const y_absl::Status& b) { - if (IsInlined(a.rep_) != IsInlined(b.rep_)) return false; - if (a.message() != b.message()) return false; - if (a.raw_code() != b.raw_code()) return false; - if (a.GetPayloads() == b.GetPayloads()) return true; - - const status_internal::Payloads no_payloads; - const status_internal::Payloads* larger_payloads = - a.GetPayloads() ? a.GetPayloads() : &no_payloads; - const status_internal::Payloads* smaller_payloads = - b.GetPayloads() ? b.GetPayloads() : &no_payloads; - if (larger_payloads->size() < smaller_payloads->size()) { - std::swap(larger_payloads, smaller_payloads); - } - if ((larger_payloads->size() - smaller_payloads->size()) > 1) return false; - // Payloads can be ordered differently, so we can't just compare payload - // vectors. - for (const auto& payload : *larger_payloads) { - - bool found = false; - for (const auto& other_payload : *smaller_payloads) { - if (payload.type_url == other_payload.type_url) { - if (payload.payload != other_payload.payload) { - return false; - } - found = true; - break; - } - } - if (!found) return false; - } - return true; -} - + UnrefNonInlined(rep_i); + } +} + +bool Status::EqualsSlow(const y_absl::Status& a, const y_absl::Status& b) { + if (IsInlined(a.rep_) != IsInlined(b.rep_)) return false; + if (a.message() != b.message()) return false; + if (a.raw_code() != b.raw_code()) return false; + if (a.GetPayloads() == b.GetPayloads()) return true; + + const status_internal::Payloads no_payloads; + const status_internal::Payloads* larger_payloads = + a.GetPayloads() ? a.GetPayloads() : &no_payloads; + const status_internal::Payloads* smaller_payloads = + b.GetPayloads() ? b.GetPayloads() : &no_payloads; + if (larger_payloads->size() < smaller_payloads->size()) { + std::swap(larger_payloads, smaller_payloads); + } + if ((larger_payloads->size() - smaller_payloads->size()) > 1) return false; + // Payloads can be ordered differently, so we can't just compare payload + // vectors. + for (const auto& payload : *larger_payloads) { + + bool found = false; + for (const auto& other_payload : *smaller_payloads) { + if (payload.type_url == other_payload.type_url) { + if (payload.payload != other_payload.payload) { + return false; + } + found = true; + break; + } + } + if (!found) return false; + } + return true; +} + TString Status::ToStringSlow(StatusToStringMode mode) const { - TString text; - y_absl::StrAppend(&text, y_absl::StatusCodeToString(code()), ": ", message()); - + TString text; + y_absl::StrAppend(&text, y_absl::StatusCodeToString(code()), ": ", message()); + const bool with_payload = (mode & StatusToStringMode::kWithPayload) == StatusToStringMode::kWithPayload; @@ -304,141 +304,141 @@ TString Status::ToStringSlow(StatusToStringMode mode) const { }); } - return text; -} - -std::ostream& operator<<(std::ostream& os, const Status& x) { + return text; +} + +std::ostream& operator<<(std::ostream& os, const Status& x) { os << x.ToString(StatusToStringMode::kWithEverything); - return os; -} - -Status AbortedError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kAborted, message); -} - -Status AlreadyExistsError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kAlreadyExists, message); -} - -Status CancelledError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kCancelled, message); -} - -Status DataLossError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kDataLoss, message); -} - -Status DeadlineExceededError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kDeadlineExceeded, message); -} - -Status FailedPreconditionError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kFailedPrecondition, message); -} - -Status InternalError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kInternal, message); -} - -Status InvalidArgumentError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kInvalidArgument, message); -} - -Status NotFoundError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kNotFound, message); -} - -Status OutOfRangeError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kOutOfRange, message); -} - -Status PermissionDeniedError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kPermissionDenied, message); -} - -Status ResourceExhaustedError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kResourceExhausted, message); -} - -Status UnauthenticatedError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kUnauthenticated, message); -} - -Status UnavailableError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kUnavailable, message); -} - -Status UnimplementedError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kUnimplemented, message); -} - -Status UnknownError(y_absl::string_view message) { - return Status(y_absl::StatusCode::kUnknown, message); -} - -bool IsAborted(const Status& status) { - return status.code() == y_absl::StatusCode::kAborted; -} - -bool IsAlreadyExists(const Status& status) { - return status.code() == y_absl::StatusCode::kAlreadyExists; -} - -bool IsCancelled(const Status& status) { - return status.code() == y_absl::StatusCode::kCancelled; -} - -bool IsDataLoss(const Status& status) { - return status.code() == y_absl::StatusCode::kDataLoss; -} - -bool IsDeadlineExceeded(const Status& status) { - return status.code() == y_absl::StatusCode::kDeadlineExceeded; -} - -bool IsFailedPrecondition(const Status& status) { - return status.code() == y_absl::StatusCode::kFailedPrecondition; -} - -bool IsInternal(const Status& status) { - return status.code() == y_absl::StatusCode::kInternal; -} - -bool IsInvalidArgument(const Status& status) { - return status.code() == y_absl::StatusCode::kInvalidArgument; -} - -bool IsNotFound(const Status& status) { - return status.code() == y_absl::StatusCode::kNotFound; -} - -bool IsOutOfRange(const Status& status) { - return status.code() == y_absl::StatusCode::kOutOfRange; -} - -bool IsPermissionDenied(const Status& status) { - return status.code() == y_absl::StatusCode::kPermissionDenied; -} - -bool IsResourceExhausted(const Status& status) { - return status.code() == y_absl::StatusCode::kResourceExhausted; -} - -bool IsUnauthenticated(const Status& status) { - return status.code() == y_absl::StatusCode::kUnauthenticated; -} - -bool IsUnavailable(const Status& status) { - return status.code() == y_absl::StatusCode::kUnavailable; -} - -bool IsUnimplemented(const Status& status) { - return status.code() == y_absl::StatusCode::kUnimplemented; -} - -bool IsUnknown(const Status& status) { - return status.code() == y_absl::StatusCode::kUnknown; -} - -ABSL_NAMESPACE_END -} // namespace y_absl + return os; +} + +Status AbortedError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kAborted, message); +} + +Status AlreadyExistsError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kAlreadyExists, message); +} + +Status CancelledError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kCancelled, message); +} + +Status DataLossError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kDataLoss, message); +} + +Status DeadlineExceededError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kDeadlineExceeded, message); +} + +Status FailedPreconditionError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kFailedPrecondition, message); +} + +Status InternalError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kInternal, message); +} + +Status InvalidArgumentError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kInvalidArgument, message); +} + +Status NotFoundError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kNotFound, message); +} + +Status OutOfRangeError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kOutOfRange, message); +} + +Status PermissionDeniedError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kPermissionDenied, message); +} + +Status ResourceExhaustedError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kResourceExhausted, message); +} + +Status UnauthenticatedError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kUnauthenticated, message); +} + +Status UnavailableError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kUnavailable, message); +} + +Status UnimplementedError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kUnimplemented, message); +} + +Status UnknownError(y_absl::string_view message) { + return Status(y_absl::StatusCode::kUnknown, message); +} + +bool IsAborted(const Status& status) { + return status.code() == y_absl::StatusCode::kAborted; +} + +bool IsAlreadyExists(const Status& status) { + return status.code() == y_absl::StatusCode::kAlreadyExists; +} + +bool IsCancelled(const Status& status) { + return status.code() == y_absl::StatusCode::kCancelled; +} + +bool IsDataLoss(const Status& status) { + return status.code() == y_absl::StatusCode::kDataLoss; +} + +bool IsDeadlineExceeded(const Status& status) { + return status.code() == y_absl::StatusCode::kDeadlineExceeded; +} + +bool IsFailedPrecondition(const Status& status) { + return status.code() == y_absl::StatusCode::kFailedPrecondition; +} + +bool IsInternal(const Status& status) { + return status.code() == y_absl::StatusCode::kInternal; +} + +bool IsInvalidArgument(const Status& status) { + return status.code() == y_absl::StatusCode::kInvalidArgument; +} + +bool IsNotFound(const Status& status) { + return status.code() == y_absl::StatusCode::kNotFound; +} + +bool IsOutOfRange(const Status& status) { + return status.code() == y_absl::StatusCode::kOutOfRange; +} + +bool IsPermissionDenied(const Status& status) { + return status.code() == y_absl::StatusCode::kPermissionDenied; +} + +bool IsResourceExhausted(const Status& status) { + return status.code() == y_absl::StatusCode::kResourceExhausted; +} + +bool IsUnauthenticated(const Status& status) { + return status.code() == y_absl::StatusCode::kUnauthenticated; +} + +bool IsUnavailable(const Status& status) { + return status.code() == y_absl::StatusCode::kUnavailable; +} + +bool IsUnimplemented(const Status& status) { + return status.code() == y_absl::StatusCode::kUnimplemented; +} + +bool IsUnknown(const Status& status) { + return status.code() == y_absl::StatusCode::kUnknown; +} + +ABSL_NAMESPACE_END +} // namespace y_absl |