Skip to content

Commit 170f877

Browse files
Abseil Teamcopybara-github
authored andcommitted
Add absl::Status::MakeNonOkStatusWithOkCode() and absl::status_internal::StatusPrivateAccessor for private/internal use
PiperOrigin-RevId: 892483178 Change-Id: Ia439eb6bc941f75250c116eaf0dfb2924ec21c29
1 parent 4ff7ff9 commit 170f877

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

absl/status/internal/status_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ enum class StatusCode : int;
5959
enum class StatusToStringMode : int;
6060

6161
namespace status_internal {
62+
#ifndef SWIG
63+
class StatusPrivateAccessor;
64+
#endif // !SWIG
6265

6366
// Container for status payloads.
6467
struct Payload {

absl/status/status.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ const std::string* absl_nonnull Status::MovedFromString() {
105105
return kMovedFrom.get();
106106
}
107107

108+
absl::Status absl::Status::MakeNonOkStatusWithOkCode(
109+
absl::string_view message) {
110+
return absl::Status(
111+
absl::Status::PointerToRep(new absl::status_internal::StatusRep(
112+
absl::StatusCode::kOk, message, nullptr)));
113+
}
114+
108115
uintptr_t Status::MakeRep(uintptr_t inlined_rep, absl::string_view msg,
109116
absl::SourceLocation loc) {
110117
bool ok = inlined_rep == CodeToInlinedRep(absl::StatusCode::kOk);

absl/status/status.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,16 @@ class ABSL_ATTRIBUTE_TRIVIAL_ABI Status final {
690690
private:
691691
friend Status CancelledError();
692692

693+
#ifndef SWIG
694+
// Returns a `Status` object which is not `ok()` but
695+
// `code() == absl::StatusCode::kOk`. This is necessary to be compatible with
696+
// `Status` objects created with an error code in a custom `ErrorSpace` that
697+
// is mapped to the canonical code `absl::StatusCode::kOk`.
698+
static Status MakeNonOkStatusWithOkCode(absl::string_view message);
699+
700+
friend class absl::status_internal::StatusPrivateAccessor;
701+
#endif // !SWIG
702+
693703
// Creates a status in the canonical error space with the specified
694704
// code, and an empty error message.
695705
explicit Status(absl::StatusCode code);

0 commit comments

Comments
 (0)