GRPC C++  1.24.0
status.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCPP_IMPL_CODEGEN_STATUS_H
20 #define GRPCPP_IMPL_CODEGEN_STATUS_H
21 
25 
26 namespace grpc {
27 
31 class Status {
32  public:
34  Status() : code_(StatusCode::OK) {
35  // Static assertions to make sure that the C++ API value correctly
36  // maps to the core surface API value
37  static_assert(StatusCode::OK == static_cast<StatusCode>(GRPC_STATUS_OK),
38  "Mismatched status code");
39  static_assert(
40  StatusCode::CANCELLED == static_cast<StatusCode>(GRPC_STATUS_CANCELLED),
41  "Mismatched status code");
42  static_assert(
43  StatusCode::UNKNOWN == static_cast<StatusCode>(GRPC_STATUS_UNKNOWN),
44  "Mismatched status code");
45  static_assert(StatusCode::INVALID_ARGUMENT ==
46  static_cast<StatusCode>(GRPC_STATUS_INVALID_ARGUMENT),
47  "Mismatched status code");
48  static_assert(StatusCode::DEADLINE_EXCEEDED ==
49  static_cast<StatusCode>(GRPC_STATUS_DEADLINE_EXCEEDED),
50  "Mismatched status code");
51  static_assert(
52  StatusCode::NOT_FOUND == static_cast<StatusCode>(GRPC_STATUS_NOT_FOUND),
53  "Mismatched status code");
54  static_assert(StatusCode::ALREADY_EXISTS ==
55  static_cast<StatusCode>(GRPC_STATUS_ALREADY_EXISTS),
56  "Mismatched status code");
57  static_assert(StatusCode::PERMISSION_DENIED ==
58  static_cast<StatusCode>(GRPC_STATUS_PERMISSION_DENIED),
59  "Mismatched status code");
60  static_assert(StatusCode::UNAUTHENTICATED ==
61  static_cast<StatusCode>(GRPC_STATUS_UNAUTHENTICATED),
62  "Mismatched status code");
63  static_assert(StatusCode::RESOURCE_EXHAUSTED ==
64  static_cast<StatusCode>(GRPC_STATUS_RESOURCE_EXHAUSTED),
65  "Mismatched status code");
66  static_assert(StatusCode::FAILED_PRECONDITION ==
67  static_cast<StatusCode>(GRPC_STATUS_FAILED_PRECONDITION),
68  "Mismatched status code");
69  static_assert(
70  StatusCode::ABORTED == static_cast<StatusCode>(GRPC_STATUS_ABORTED),
71  "Mismatched status code");
72  static_assert(StatusCode::OUT_OF_RANGE ==
73  static_cast<StatusCode>(GRPC_STATUS_OUT_OF_RANGE),
74  "Mismatched status code");
75  static_assert(StatusCode::UNIMPLEMENTED ==
76  static_cast<StatusCode>(GRPC_STATUS_UNIMPLEMENTED),
77  "Mismatched status code");
78  static_assert(
79  StatusCode::INTERNAL == static_cast<StatusCode>(GRPC_STATUS_INTERNAL),
80  "Mismatched status code");
81  static_assert(StatusCode::UNAVAILABLE ==
82  static_cast<StatusCode>(GRPC_STATUS_UNAVAILABLE),
83  "Mismatched status code");
84  static_assert(
85  StatusCode::DATA_LOSS == static_cast<StatusCode>(GRPC_STATUS_DATA_LOSS),
86  "Mismatched status code");
87  }
88 
92  : code_(code), error_message_(error_message) {}
93 
99  : code_(code),
100  error_message_(error_message),
101  binary_error_details_(error_details) {}
102 
103  // Pre-defined special status objects.
105  static const Status& OK;
107  static const Status& CANCELLED;
108 
110  StatusCode error_code() const { return code_; }
112  grpc::string error_message() const { return error_message_; }
114  // Usually it contains a serialized google.rpc.Status proto.
115  grpc::string error_details() const { return binary_error_details_; }
116 
118  bool ok() const { return code_ == StatusCode::OK; }
119 
120  // Ignores any errors. This method does nothing except potentially suppress
121  // complaints from any tools that are checking that errors are not dropped on
122  // the floor.
123  void IgnoreError() const {}
124 
125  private:
126  StatusCode code_;
127  grpc::string error_message_;
128  grpc::string binary_error_details_;
129 };
130 
131 } // namespace grpc
132 
133 #endif // GRPCPP_IMPL_CODEGEN_STATUS_H
The caller does not have permission to execute the specified operation.
Definition: status_code_enum.h:62
The service is currently unavailable.
Definition: status_code_enum.h:132
Deadline expired before operation could complete.
Definition: status.h:51
Some entity that we attempted to create (e.g., file or directory) already exists. ...
Definition: status_code_enum.h:55
std::string string
Definition: config.h:35
Operation was rejected because the system is not in a state required for the operation&#39;s execution...
Definition: status.h:95
Operation was rejected because the system is not in a state required for the operation&#39;s execution...
Definition: status_code_enum.h:90
static const Status & CANCELLED
A CANCELLED pre-defined instance.
Definition: status.h:107
Unrecoverable data loss or corruption.
Definition: status_code_enum.h:135
Operation was attempted past the valid range.
Definition: status.h:119
The operation was cancelled (typically by the caller).
Definition: status.h:31
Not an error; returned on success.
Definition: status_code_enum.h:26
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out ...
Definition: status.h:74
StatusCode
Definition: status_code_enum.h:24
grpc::string error_message() const
Return the instance&#39;s error message.
Definition: status.h:112
Status()
Construct an OK instance.
Definition: status.h:34
StatusCode error_code() const
Return the instance&#39;s error code.
Definition: status.h:110
Not an error; returned on success.
Definition: status.h:28
Unknown error.
Definition: status.h:38
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
The service is currently unavailable.
Definition: status.h:141
The operation was aborted, typically due to a concurrency issue like sequencer check failures...
Definition: status_code_enum.h:97
The operation was cancelled (typically by the caller).
Definition: status_code_enum.h:29
Deadline expired before operation could complete.
Definition: status_code_enum.h:48
The request does not have valid authentication credentials for the operation.
Definition: status.h:70
Client specified an invalid argument.
Definition: status_code_enum.h:41
Unrecoverable data loss or corruption.
Definition: status.h:144
The operation was aborted, typically due to a concurrency issue like sequencer check failures...
Definition: status.h:102
bool ok() const
Is the status OK?
Definition: status.h:118
Some entity that we attempted to create (e.g., file or directory) already exists. ...
Definition: status.h:58
The caller does not have permission to execute the specified operation.
Definition: status.h:66
Internal errors.
Definition: status.h:127
Did it work? If it didn&#39;t, why?
Definition: status.h:31
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:115
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out ...
Definition: status_code_enum.h:70
Status(StatusCode code, const grpc::string &error_message)
Construct an instance with associated code and error_message.
Definition: status.h:91
Some requested entity (e.g., file or directory) was not found.
Definition: status_code_enum.h:51
static const Status & OK
An OK pre-defined instance.
Definition: status.h:105
Unknown error.
Definition: status_code_enum.h:35
Some requested entity (e.g., file or directory) was not found.
Definition: status.h:54
Operation was attempted past the valid range.
Definition: status_code_enum.h:112
Internal errors.
Definition: status_code_enum.h:119
The request does not have valid authentication credentials for the operation.
Definition: status_code_enum.h:66
Client specified an invalid argument.
Definition: status.h:44
void IgnoreError() const
Definition: status.h:123
Operation is not implemented or not supported/enabled in this service.
Definition: status.h:122
grpc::string error_details() const
Return the (binary) error details.
Definition: status.h:115
Status(StatusCode code, const grpc::string &error_message, const grpc::string &error_details)
Construct an instance with code, error_message and error_details.
Definition: status.h:97