15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STATUS_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STATUS_H
18#include "google/cloud/version.h"
19#include "absl/types/optional.h"
23#include <unordered_map>
30
31
32
33
34
194std::ostream& operator<<(std::ostream& os,
StatusCode code);
198void SetPayload(
Status&, std::string key, std::string payload);
199absl::optional<std::string> GetPayload(
Status const&, std::string
const& key);
203
204
205
206
210
211
212
213
214
218
219
220
221
222
223
224 explicit ErrorInfo(std::string reason, std::string domain,
225 std::unordered_map<std::string, std::string> metadata)
226 : reason_(std::move(reason)),
227 domain_(std::move(domain)),
228 metadata_(std::move(metadata)) {}
231
232
233
234
235
236
237
238 std::string
const&
reason()
const {
return reason_; }
241
242
243
244
245
246
247
248
249
250
251
252 std::string
const&
domain()
const {
return domain_; }
255
256
257
258
259
260
261
262
263
264
265
266 std::unordered_map<std::string, std::string>
const&
metadata()
const {
276 std::unordered_map<std::string, std::string> metadata_;
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
303
304
310
311
317
318
319
320
321
322
323
324
328 bool ok()
const {
return !impl_; }
334
335
336
337
338 std::string
const&
message()
const;
341
342
343
344
345
357 friend void internal::SetPayload(
Status&, std::string, std::string);
358 friend absl::optional<std::string> internal::GetPayload(
Status const&,
363 std::unique_ptr<Impl> impl_;
367
368
369
370
371
372std::ostream& operator<<(std::ostream& os,
Status const& s);
375
376
Describes the cause of the error with structured details.
Definition: status.h:207
friend bool operator!=(ErrorInfo const &, ErrorInfo const &)
ErrorInfo(std::string reason, std::string domain, std::unordered_map< std::string, std::string > metadata)
Constructor.
Definition: status.h:224
friend bool operator==(ErrorInfo const &, ErrorInfo const &)
ErrorInfo()=default
Default constructor.
std::unordered_map< std::string, std::string > const & metadata() const
Additional structured details about this error.
Definition: status.h:266
std::string const & domain() const
The logical grouping to which the "reason" belongs.
Definition: status.h:252
std::string const & reason() const
The reason of the error.
Definition: status.h:238
A runtime error that wraps a google::cloud::Status.
Definition: status.h:377
RuntimeStatusError(Status status)
Constructor from a Status.
Status const & status() const
Returns the original status.
Definition: status.h:383
Represents success or an error with info about the error.
Definition: status.h:295
ErrorInfo const & error_info() const
Returns the additional error info associated with the status.
bool ok() const
Returns true if the status code is StatusCode::kOk.
Definition: status.h:328
Status & operator=(Status &&) noexcept
friend bool operator!=(Status const &a, Status const &b)
Definition: status.h:351
Status & operator=(Status const &)
friend bool operator==(Status const &a, Status const &b)
Definition: status.h:348
std::string const & message() const
Returns the message associated with the status.
StatusCode code() const
Returns the status code.
Status()
Default constructor, initializes to StatusCode::kOk.
Status(StatusCode code, std::string message, ErrorInfo info={})
Construct from a status code, message and (optional) error info.
Status(Status &&) noexcept
Contains all the Google Cloud C++ Library APIs.
Definition: async_operation.h:23
StatusCode
Well-known status codes with grpc::StatusCode-compatible values.
Definition: status.h:35
@ kFailedPrecondition
kFailedPrecondition (gRPC code FAILED_PRECONDITION) indicates that the operation was rejected because...
@ kUnknown
kUnknown (gRPC code UNKNOWN) indicates an unknown error occurred.
@ kDataLoss
kDataLoss (gRPC code DATA_LOSS) indicates that unrecoverable data loss or corruption has occurred.
@ kDeadlineExceeded
kDeadlineExceeded (gRPC code DEADLINE_EXCEEDED) indicates a deadline expired before the operation cou...
@ kResourceExhausted
kResourceExhausted (gRPC code RESOURCE_EXHAUSTED) indicates some resource has been exhausted.
@ kInvalidArgument
kInvalidArgument (gRPC code INVALID_ARGUMENT) indicates the caller specified an invalid argument,...
@ kUnavailable
kUnavailable (gRPC code UNAVAILABLE) indicates the service is currently unavailable and that this is ...
@ kUnimplemented
kUnimplemented (gRPC code UNIMPLEMENTED) indicates the operation is not implemented or supported in t...
@ kInternal
kInternal (gRPC code INTERNAL) indicates an internal error has occurred and some invariants expected ...
@ kCancelled
kCancelled (gRPC code CANCELLED) indicates the operation was cancelled, typically by the caller.
@ kAlreadyExists
kAlreadyExists (gRPC codeALREADY_EXISTS`) indicates that the entity a caller attempted to create (suc...
@ kNotFound
kNotFound (gRPC code NOT_FOUND) indicates some requested entity (such as a file or directory) was not...
@ kAborted
kAborted (gRPC code ABORTED) indicates the operation was aborted.
@ kUnauthenticated
kUnauthenticated (gRPC code UNAUTHENTICATED) indicates that the request does not have valid authentic...
@ kPermissionDenied
kPermissionDenied (gRPC code PERMISSION_DENIED) indicates that the caller does not have permission to...
@ kOk
Not an error; returned on success.
@ kOutOfRange
kOutOfRange (gRPC code OUT_OF_RANGE) indicates the operation was attempted past the valid range,...
std::string StatusCodeToString(StatusCode code)
Convert code to a human readable string.
Definition: async_operation.h:22
#define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Definition: version.h:45
#define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
Definition: version.h:43