third_party/protobuf/src/google/protobuf/stubs/status.cc
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 #include <google/protobuf/stubs/status.h>
31 
32 #include <ostream>
33 #include <stdio.h>
34 #include <string>
35 #include <utility>
36 
37 namespace google {
38 namespace protobuf {
39 namespace util {
40 namespace status_internal {
41 namespace {
42 
44  switch (code) {
45  case StatusCode::kOk:
46  return "OK";
48  return "CANCELLED";
50  return "UNKNOWN";
52  return "INVALID_ARGUMENT";
54  return "DEADLINE_EXCEEDED";
56  return "NOT_FOUND";
58  return "ALREADY_EXISTS";
60  return "PERMISSION_DENIED";
62  return "UNAUTHENTICATED";
64  return "RESOURCE_EXHAUSTED";
66  return "FAILED_PRECONDITION";
68  return "ABORTED";
70  return "OUT_OF_RANGE";
72  return "UNIMPLEMENTED";
74  return "INTERNAL";
76  return "UNAVAILABLE";
78  return "DATA_LOSS";
79  }
80 
81  // No default clause, clang will abort if a code is missing from
82  // above switch.
83  return "UNKNOWN";
84 }
85 
86 } // namespace
87 
88 Status::Status() : error_code_(StatusCode::kOk) {}
89 
90 Status::Status(StatusCode error_code, StringPiece error_message)
91  : error_code_(error_code) {
92  if (error_code != StatusCode::kOk) {
93  error_message_ = error_message.ToString();
94  }
95 }
96 
97 Status::Status(const Status& other)
98  : error_code_(other.error_code_), error_message_(other.error_message_) {
99 }
100 
102  error_code_ = other.error_code_;
104  return *this;
105 }
106 
107 bool Status::operator==(const Status& x) const {
108  return error_code_ == x.error_code_ &&
109  error_message_ == x.error_message_;
110 }
111 
113  if (error_code_ == StatusCode::kOk) {
114  return "OK";
115  } else {
116  if (error_message_.empty()) {
118  } else {
120  }
121  }
122 }
123 
124 Status OkStatus() { return Status(); }
125 
126 std::ostream& operator<<(std::ostream& os, const Status& x) {
127  os << x.ToString();
128  return os;
129 }
130 
131 bool IsAborted(const Status& status) {
132  return status.code() == StatusCode::kAborted;
133 }
134 
137 }
138 
139 bool IsCancelled(const Status& status) {
140  return status.code() == StatusCode::kCancelled;
141 }
142 
143 bool IsDataLoss(const Status& status) {
144  return status.code() == StatusCode::kDataLoss;
145 }
146 
149 }
150 
153 }
154 
155 bool IsInternal(const Status& status) {
156  return status.code() == StatusCode::kInternal;
157 }
158 
161 }
162 
163 bool IsNotFound(const Status& status) {
164  return status.code() == StatusCode::kNotFound;
165 }
166 
167 bool IsOutOfRange(const Status& status) {
168  return status.code() == StatusCode::kOutOfRange;
169 }
170 
173 }
174 
177 }
178 
181 }
182 
185 }
186 
189 }
190 
191 bool IsUnknown(const Status& status) {
192  return status.code() == StatusCode::kUnknown;
193 }
194 
197 }
198 
201 }
202 
205 }
206 
209 }
210 
213 }
214 
217 }
218 
221 }
222 
225 }
226 
229 }
230 
233 }
234 
237 }
238 
241 }
242 
245 }
246 
249 }
250 
253 }
254 
257 }
258 
259 } // namespace status_internal
260 } // namespace util
261 } // namespace protobuf
262 } // namespace google
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
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
google::protobuf::util::status_internal::IsUnauthenticated
bool IsUnauthenticated(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:179
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
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
google::protobuf::util::status_internal::Status::operator==
bool operator==(const Status &x) const
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:107
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
status
absl::Status status
Definition: rls.cc:251
google::protobuf::util::status_internal::Status::operator=
Status & operator=(const Status &x)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:101
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::Status::Status
Status()
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:88
google::protobuf::util::status_internal::StatusCode::kDeadlineExceeded
@ kDeadlineExceeded
google::protobuf::util::status_internal::Status::ToString
std::string ToString() const
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:112
google::protobuf::util::status_internal::IsInvalidArgument
bool IsInvalidArgument(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:159
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
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
google::protobuf::util::status_internal::IsResourceExhausted
bool IsResourceExhausted(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:175
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
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
grpc::StatusCodeToString
absl::string_view StatusCodeToString(grpc_status_code code)
Definition: context.cc:119
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
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
google::protobuf::util::status_internal::IsCancelled
bool IsCancelled(const Status &status)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:139
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
google::protobuf::util::status_internal::AbortedError
Status AbortedError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:195
google::protobuf::util::status_internal::StatusCode::kInvalidArgument
@ kInvalidArgument
google::protobuf::StringPiece::ToString
string ToString() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/stringpiece.h:313
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
google::protobuf::util::status_internal::Status::error_message_
std::string error_message_
Definition: third_party/protobuf/src/google/protobuf/stubs/status.h:97
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
google::protobuf::util::status_internal::ResourceExhaustedError
Status ResourceExhaustedError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:239
code
Definition: bloaty/third_party/zlib/contrib/infback9/inftree9.h:24
google::protobuf::util::status_internal::InternalError
Status InternalError(StringPiece message)
Definition: third_party/protobuf/src/google/protobuf/stubs/status.cc:219
absl::Status::code
absl::StatusCode code() const
Definition: third_party/abseil-cpp/absl/status/status.cc:233
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


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