third_party/protobuf/src/google/protobuf/stubs/status.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_STUBS_STATUS_H_
32 #define GOOGLE_PROTOBUF_STUBS_STATUS_H_
33 
34 #include <string>
35 
36 #include <google/protobuf/stubs/stringpiece.h>
37 
38 #include <google/protobuf/port_def.inc>
39 
40 namespace google {
41 namespace protobuf {
42 namespace util {
43 namespace status_internal {
44 
45 // These values must match error codes defined in google/rpc/code.proto.
46 enum class StatusCode : int {
47  kOk = 0,
48  kCancelled = 1,
49  kUnknown = 2,
50  kInvalidArgument = 3,
52  kNotFound = 5,
53  kAlreadyExists = 6,
55  kUnauthenticated = 16,
58  kAborted = 10,
59  kOutOfRange = 11,
60  kUnimplemented = 12,
61  kInternal = 13,
62  kUnavailable = 14,
63  kDataLoss = 15,
64 };
65 
66 class PROTOBUF_EXPORT Status {
67  public:
68  // Creates a "successful" status.
69  Status();
70 
71  // Create a status in the canonical error space with the specified
72  // code, and error message. If "code == 0", error_message is
73  // ignored and a Status object identical to Status::kOk is
74  // constructed.
75  Status(StatusCode error_code, StringPiece error_message);
76  Status(const Status&);
77  Status& operator=(const Status& x);
78  ~Status() {}
79 
80  // Accessor
81  bool ok() const { return error_code_ == StatusCode::kOk; }
82  StatusCode code() const { return error_code_; }
83  StringPiece message() const {
84  return error_message_;
85  }
86 
87  bool operator==(const Status& x) const;
88  bool operator!=(const Status& x) const {
89  return !operator==(x);
90  }
91 
92  // Return a combination of the error code name and message.
93  std::string ToString() const;
94 
95  private:
98 };
99 
100 // Returns an OK status, equivalent to a default constructed instance. Prefer
101 // usage of `OkStatus()` when constructing such an OK status.
102 PROTOBUF_EXPORT Status OkStatus();
103 
104 // Prints a human-readable representation of 'x' to 'os'.
105 PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x);
106 
107 // These convenience functions return `true` if a given status matches the
108 // `StatusCode` error code of its associated function.
109 PROTOBUF_EXPORT bool IsAborted(const Status& status);
110 PROTOBUF_EXPORT bool IsAlreadyExists(const Status& status);
111 PROTOBUF_EXPORT bool IsCancelled(const Status& status);
112 PROTOBUF_EXPORT bool IsDataLoss(const Status& status);
113 PROTOBUF_EXPORT bool IsDeadlineExceeded(const Status& status);
114 PROTOBUF_EXPORT bool IsFailedPrecondition(const Status& status);
115 PROTOBUF_EXPORT bool IsInternal(const Status& status);
116 PROTOBUF_EXPORT bool IsInvalidArgument(const Status& status);
117 PROTOBUF_EXPORT bool IsNotFound(const Status& status);
118 PROTOBUF_EXPORT bool IsOutOfRange(const Status& status);
119 PROTOBUF_EXPORT bool IsPermissionDenied(const Status& status);
120 PROTOBUF_EXPORT bool IsResourceExhausted(const Status& status);
121 PROTOBUF_EXPORT bool IsUnauthenticated(const Status& status);
122 PROTOBUF_EXPORT bool IsUnavailable(const Status& status);
123 PROTOBUF_EXPORT bool IsUnimplemented(const Status& status);
124 PROTOBUF_EXPORT bool IsUnknown(const Status& status);
125 
126 // These convenience functions create an `Status` object with an error code as
127 // indicated by the associated function name, using the error message passed in
128 // `message`.
129 //
130 // These functions are intentionally named `*Error` rather than `*Status` to
131 // match the names from Abseil:
132 // https://github.com/abseil/abseil-cpp/blob/2e9532cc6c701a8323d0cffb468999ab804095ab/absl/status/status.h#L716
133 PROTOBUF_EXPORT Status AbortedError(StringPiece message);
135 PROTOBUF_EXPORT Status CancelledError(StringPiece message);
136 PROTOBUF_EXPORT Status DataLossError(StringPiece message);
139 PROTOBUF_EXPORT Status InternalError(StringPiece message);
141 PROTOBUF_EXPORT Status NotFoundError(StringPiece message);
142 PROTOBUF_EXPORT Status OutOfRangeError(StringPiece message);
146 PROTOBUF_EXPORT Status UnavailableError(StringPiece message);
148 PROTOBUF_EXPORT Status UnknownError(StringPiece message);
149 
150 } // namespace status_internal
151 
154 
171 
189 
190 } // namespace util
191 } // namespace protobuf
192 } // namespace google
193 
194 #include <google/protobuf/port_undef.inc>
195 
196 #endif // GOOGLE_PROTOBUF_STUBS_STATUS_H_
google::protobuf::util::status_internal::FailedPreconditionError
Status FailedPreconditionError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:215
google::protobuf::util::status_internal::InvalidArgumentError
Status InvalidArgumentError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:223
absl::InvalidArgumentError
Status InvalidArgumentError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:351
google::protobuf::util::status_internal::StatusCode::kUnknown
@ kUnknown
google::protobuf::util::status_internal::StatusCode::kCancelled
@ kCancelled
google::protobuf::util::status_internal::IsOutOfRange
bool IsOutOfRange(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:167
google::protobuf::util::status_internal::IsDeadlineExceeded
bool IsDeadlineExceeded(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:147
absl::AbortedError
Status AbortedError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:323
google::protobuf::util::status_internal::IsUnauthenticated
bool IsUnauthenticated(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:179
absl::IsDeadlineExceeded
bool IsDeadlineExceeded(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:403
absl::IsUnavailable
bool IsUnavailable(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:439
google::protobuf::util::status_internal::OkStatus
Status OkStatus()
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:124
google::protobuf::util::status_internal::IsUnimplemented
bool IsUnimplemented(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:187
google::protobuf::util::status_internal::NotFoundError
Status NotFoundError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:227
google::protobuf::util::status_internal::StatusCode::kResourceExhausted
@ kResourceExhausted
absl::IsInternal
bool IsInternal(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:411
absl::CancelledError
Status CancelledError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:331
absl::IsOutOfRange
bool IsOutOfRange(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:423
google::protobuf::util::status_internal::IsUnavailable
bool IsUnavailable(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:183
google::protobuf::util::status_internal::StatusCode::kPermissionDenied
@ kPermissionDenied
google::protobuf::util::status_internal::StatusCode::kOk
@ kOk
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
absl::OkStatus
Status OkStatus()
Definition: third_party/abseil-cpp/absl/status/status.h:882
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
status
absl::Status status
Definition: rls.cc:251
absl::InternalError
Status InternalError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:347
absl::IsDataLoss
bool IsDataLoss(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:399
google::protobuf::util::status_internal::StatusCode::kAlreadyExists
@ kAlreadyExists
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
google::protobuf::util::status_internal::StatusCode::kDeadlineExceeded
@ kDeadlineExceeded
absl::PermissionDeniedError
Status PermissionDeniedError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:363
google::protobuf::util::status_internal::IsInvalidArgument
bool IsInvalidArgument(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:159
absl::UnauthenticatedError
Status UnauthenticatedError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:371
error_message_
const std::string error_message_
Definition: boringssl-with-bazel/src/third_party/googletest/src/gtest.cc:451
google::protobuf::util::status_internal::CancelledError
Status CancelledError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:203
google::protobuf::util::status_internal::IsAborted
bool IsAborted(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:131
google::protobuf::util::status_internal::DeadlineExceededError
Status DeadlineExceededError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:211
google::protobuf::util::status_internal::AlreadyExistsError
Status AlreadyExistsError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:199
google::protobuf::util::status_internal::Status
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:66
xds_interop_client.int
int
Definition: xds_interop_client.py:113
absl::IsUnknown
bool IsUnknown(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:447
google::protobuf::util::status_internal::StatusCode
StatusCode
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:46
google::protobuf::util::status_internal::StatusCode::kDataLoss
@ kDataLoss
ToString
std::string ToString(const grpc::string_ref &r)
Definition: string_ref_helper.cc:24
absl::FailedPreconditionError
Status FailedPreconditionError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:343
google::protobuf::util::status_internal::Status::ok
bool ok() const
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:81
absl::IsCancelled
bool IsCancelled(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:395
google::protobuf::util::status_internal::IsResourceExhausted
bool IsResourceExhausted(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:175
absl::IsUnauthenticated
bool IsUnauthenticated(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:435
google::protobuf::util::status_internal::UnauthenticatedError
Status UnauthenticatedError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:243
google::protobuf::StringPiece
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/stringpiece.h:180
absl::UnknownError
Status UnknownError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:383
google::protobuf::util::status_internal::StatusCode::kOutOfRange
@ kOutOfRange
google::protobuf::util::status_internal::IsInternal
bool IsInternal(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:155
absl::IsNotFound
bool IsNotFound(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:419
absl::DataLossError
Status DataLossError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:335
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
absl::IsInvalidArgument
bool IsInvalidArgument(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:415
absl::OutOfRangeError
Status OutOfRangeError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:359
google::protobuf::util::status_internal::UnimplementedError
Status UnimplementedError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:251
google::protobuf::util::status_internal::StatusCode::kUnimplemented
@ kUnimplemented
google::protobuf::util::status_internal::PermissionDeniedError
Status PermissionDeniedError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:235
google::protobuf::util::status_internal::StatusCode::kUnauthenticated
@ kUnauthenticated
google::protobuf::util::status_internal::OutOfRangeError
Status OutOfRangeError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:231
google::protobuf::util::status_internal::IsFailedPrecondition
bool IsFailedPrecondition(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:151
google::protobuf::util::status_internal::IsNotFound
bool IsNotFound(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:163
google::protobuf::util::status_internal::DataLossError
Status DataLossError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:207
google::protobuf::util::status_internal::IsUnknown
bool IsUnknown(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:191
absl::ResourceExhaustedError
Status ResourceExhaustedError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:367
google::protobuf::util::status_internal::IsCancelled
bool IsCancelled(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:139
absl::IsFailedPrecondition
bool IsFailedPrecondition(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:407
google::protobuf::util::status_internal::Status::~Status
~Status()
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:78
google::protobuf::util::status_internal::Status::error_code_
StatusCode error_code_
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:96
google::protobuf::util::status_internal::IsPermissionDenied
bool IsPermissionDenied(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:171
google::protobuf::util::status_internal::StatusCode::kNotFound
@ kNotFound
google::protobuf::util::status_internal::StatusCode::kInternal
@ kInternal
google::protobuf::util::status_internal::StatusCode::kAborted
@ kAborted
google::protobuf::util::status_internal::UnknownError
Status UnknownError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:255
google::protobuf::util::status_internal::UnavailableError
Status UnavailableError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:247
absl::IsResourceExhausted
bool IsResourceExhausted(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:431
google::protobuf::util::status_internal::AbortedError
Status AbortedError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:195
absl::DeadlineExceededError
Status DeadlineExceededError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:339
google::protobuf::util::status_internal::StatusCode::kInvalidArgument
@ kInvalidArgument
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
google::protobuf::operator==
bool operator==(const uint128 &lhs, const uint128 &rhs)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/int128.h:138
google::protobuf::util::status_internal::Status::error_message_
std::string error_message_
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:97
absl::IsUnimplemented
bool IsUnimplemented(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:443
google::protobuf::util::status_internal::Status::message
StringPiece message() const
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:83
absl::NotFoundError
Status NotFoundError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:355
absl::UnavailableError
Status UnavailableError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:375
google::protobuf::util::status_internal::StatusCode::kUnavailable
@ kUnavailable
google::protobuf::util::status_internal::operator<<
std::ostream & operator<<(std::ostream &os, const Status &x)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:126
google::protobuf::util::status_internal::IsAlreadyExists
bool IsAlreadyExists(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:135
absl::UnimplementedError
Status UnimplementedError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:379
absl::IsPermissionDenied
bool IsPermissionDenied(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:427
google::protobuf::util::status_internal::ResourceExhaustedError
Status ResourceExhaustedError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:239
google::protobuf::util::status_internal::Status::code
StatusCode code() const
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:82
absl::IsAborted
bool IsAborted(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:387
google::protobuf::util::status_internal::InternalError
Status InternalError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:219
google::protobuf::util::status_internal::Status::operator!=
bool operator!=(const Status &x) const
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:88
absl::IsAlreadyExists
bool IsAlreadyExists(const Status &status)
Definition: third_party/abseil-cpp/absl/status/status.cc:391
google::protobuf::util::status_internal::StatusCode::kFailedPrecondition
@ kFailedPrecondition
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf::util::status_internal::IsDataLoss
bool IsDataLoss(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:143
absl::AlreadyExistsError
Status AlreadyExistsError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:327


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:17