GRPC C++  1.46.2
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 
22 // IWYU pragma: private, include <grpcpp/support/status.h>
23 
27 
28 namespace grpc {
29 
33 class Status {
34  public:
36  Status() : code_(StatusCode::OK) {
37  // Static assertions to make sure that the C++ API value correctly
38  // maps to the core surface API value
39  static_assert(StatusCode::OK == static_cast<StatusCode>(GRPC_STATUS_OK),
40  "Mismatched status code");
41  static_assert(
43  "Mismatched status code");
44  static_assert(
46  "Mismatched status code");
47  static_assert(StatusCode::INVALID_ARGUMENT ==
49  "Mismatched status code");
50  static_assert(StatusCode::DEADLINE_EXCEEDED ==
52  "Mismatched status code");
53  static_assert(
55  "Mismatched status code");
56  static_assert(StatusCode::ALREADY_EXISTS ==
58  "Mismatched status code");
59  static_assert(StatusCode::PERMISSION_DENIED ==
61  "Mismatched status code");
62  static_assert(StatusCode::UNAUTHENTICATED ==
64  "Mismatched status code");
65  static_assert(StatusCode::RESOURCE_EXHAUSTED ==
67  "Mismatched status code");
68  static_assert(StatusCode::FAILED_PRECONDITION ==
70  "Mismatched status code");
71  static_assert(
73  "Mismatched status code");
74  static_assert(StatusCode::OUT_OF_RANGE ==
76  "Mismatched status code");
77  static_assert(StatusCode::UNIMPLEMENTED ==
79  "Mismatched status code");
80  static_assert(
82  "Mismatched status code");
83  static_assert(StatusCode::UNAVAILABLE ==
84  static_cast<StatusCode>(GRPC_STATUS_UNAVAILABLE),
85  "Mismatched status code");
86  static_assert(
88  "Mismatched status code");
89  }
90 
93  Status(StatusCode code, const std::string& error_message)
94  : code_(code), error_message_(error_message) {}
95 
99  Status(StatusCode code, const std::string& error_message,
100  const std::string& error_details)
101  : code_(code),
102  error_message_(error_message),
103  binary_error_details_(error_details) {}
104 
105  // Pre-defined special status objects.
107  static const Status& OK;
109  static const Status& CANCELLED;
110 
112  StatusCode error_code() const { return code_; }
114  std::string error_message() const { return error_message_; }
116  // Usually it contains a serialized google.rpc.Status proto.
117  std::string error_details() const { return binary_error_details_; }
118 
120  bool ok() const { return code_ == StatusCode::OK; }
121 
122  // Ignores any errors. This method does nothing except potentially suppress
123  // complaints from any tools that are checking that errors are not dropped on
124  // the floor.
125  void IgnoreError() const {}
126 
127  private:
128  StatusCode code_;
129  std::string error_message_;
130  std::string binary_error_details_;
131 };
132 
133 } // namespace grpc
134 
135 #endif // GRPCPP_IMPL_CODEGEN_STATUS_H
grpc::UNAVAILABLE
@ UNAVAILABLE
The service is currently unavailable.
Definition: status_code_enum.h:134
GRPC_STATUS_INTERNAL
@ GRPC_STATUS_INTERNAL
Internal errors.
Definition: status.h:129
GRPC_STATUS_ABORTED
@ GRPC_STATUS_ABORTED
The operation was aborted, typically due to a concurrency issue like sequencer check failures,...
Definition: status.h:104
status.h
GRPC_STATUS_RESOURCE_EXHAUSTED
@ GRPC_STATUS_RESOURCE_EXHAUSTED
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out ...
Definition: status.h:76
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
GRPC_STATUS_UNAUTHENTICATED
@ GRPC_STATUS_UNAUTHENTICATED
The request does not have valid authentication credentials for the operation.
Definition: status.h:72
config.h
grpc::PERMISSION_DENIED
@ PERMISSION_DENIED
The caller does not have permission to execute the specified operation.
Definition: status_code_enum.h:64
grpc::Status::Status
Status()
Construct an OK instance.
Definition: status.h:36
GRPC_STATUS_UNKNOWN
@ GRPC_STATUS_UNKNOWN
Unknown error.
Definition: status.h:40
GRPC_STATUS_UNIMPLEMENTED
@ GRPC_STATUS_UNIMPLEMENTED
Operation is not implemented or not supported/enabled in this service.
Definition: status.h:124
GRPC_STATUS_PERMISSION_DENIED
@ GRPC_STATUS_PERMISSION_DENIED
The caller does not have permission to execute the specified operation.
Definition: status.h:68
grpc::ALREADY_EXISTS
@ ALREADY_EXISTS
Some entity that we attempted to create (e.g., file or directory) already exists.
Definition: status_code_enum.h:57
grpc::Status::ok
bool ok() const
Is the status OK?
Definition: status.h:120
grpc::DATA_LOSS
@ DATA_LOSS
Unrecoverable data loss or corruption.
Definition: status_code_enum.h:137
grpc::FAILED_PRECONDITION
@ FAILED_PRECONDITION
Operation was rejected because the system is not in a state required for the operation's execution.
Definition: status_code_enum.h:92
status_code_enum.h
GRPC_STATUS_DATA_LOSS
@ GRPC_STATUS_DATA_LOSS
Unrecoverable data loss or corruption.
Definition: status.h:146
grpc::Status
Did it work? If it didn't, why?
Definition: status.h:33
GRPC_STATUS_OUT_OF_RANGE
@ GRPC_STATUS_OUT_OF_RANGE
Operation was attempted past the valid range.
Definition: status.h:121
GRPC_STATUS_INVALID_ARGUMENT
@ GRPC_STATUS_INVALID_ARGUMENT
Client specified an invalid argument.
Definition: status.h:46
grpc::Status::Status
Status(StatusCode code, const std::string &error_message, const std::string &error_details)
Construct an instance with code, error_message and error_details.
Definition: status.h:99
GRPC_STATUS_DEADLINE_EXCEEDED
@ GRPC_STATUS_DEADLINE_EXCEEDED
Deadline expired before operation could complete.
Definition: status.h:53
GRPC_STATUS_UNAVAILABLE
@ GRPC_STATUS_UNAVAILABLE
The service is currently unavailable.
Definition: status.h:143
grpc::OK
@ OK
Not an error; returned on success.
Definition: status_code_enum.h:28
grpc::Status::Status
Status(StatusCode code, const std::string &error_message)
Construct an instance with associated code and error_message.
Definition: status.h:93
grpc::Status::error_message
std::string error_message() const
Return the instance's error message.
Definition: status.h:114
grpc::StatusCode
StatusCode
Definition: status_code_enum.h:26
grpc::Status::IgnoreError
void IgnoreError() const
Definition: status.h:125
grpc::Status::CANCELLED
static const Status & CANCELLED
A CANCELLED pre-defined instance.
Definition: status.h:109
GRPC_STATUS_NOT_FOUND
@ GRPC_STATUS_NOT_FOUND
Some requested entity (e.g., file or directory) was not found.
Definition: status.h:56
grpc::Status::error_code
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:112
grpc::ABORTED
@ ABORTED
The operation was aborted, typically due to a concurrency issue like sequencer check failures,...
Definition: status_code_enum.h:99
GRPC_STATUS_OK
@ GRPC_STATUS_OK
Not an error; returned on success.
Definition: status.h:30
grpc::DEADLINE_EXCEEDED
@ DEADLINE_EXCEEDED
Deadline expired before operation could complete.
Definition: status_code_enum.h:50
grpc::Status::OK
static const Status & OK
An OK pre-defined instance.
Definition: status.h:107
grpc::UNIMPLEMENTED
@ UNIMPLEMENTED
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:117
grpc::NOT_FOUND
@ NOT_FOUND
Some requested entity (e.g., file or directory) was not found.
Definition: status_code_enum.h:53
grpc::CANCELLED
@ CANCELLED
The operation was cancelled (typically by the caller).
Definition: status_code_enum.h:31
grpc::OUT_OF_RANGE
@ OUT_OF_RANGE
Operation was attempted past the valid range.
Definition: status_code_enum.h:114
grpc::INVALID_ARGUMENT
@ INVALID_ARGUMENT
Client specified an invalid argument.
Definition: status_code_enum.h:43
grpc::UNKNOWN
@ UNKNOWN
Unknown error.
Definition: status_code_enum.h:37
grpc::RESOURCE_EXHAUSTED
@ RESOURCE_EXHAUSTED
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out ...
Definition: status_code_enum.h:72
grpc::UNAUTHENTICATED
@ UNAUTHENTICATED
The request does not have valid authentication credentials for the operation.
Definition: status_code_enum.h:68
GRPC_STATUS_CANCELLED
@ GRPC_STATUS_CANCELLED
The operation was cancelled (typically by the caller).
Definition: status.h:33
GRPC_STATUS_FAILED_PRECONDITION
@ GRPC_STATUS_FAILED_PRECONDITION
Operation was rejected because the system is not in a state required for the operation's execution.
Definition: status.h:97
grpc::Status::error_details
std::string error_details() const
Return the (binary) error details.
Definition: status.h:117
grpc::INTERNAL
@ INTERNAL
Internal errors.
Definition: status_code_enum.h:121
GRPC_STATUS_ALREADY_EXISTS
@ GRPC_STATUS_ALREADY_EXISTS
Some entity that we attempted to create (e.g., file or directory) already exists.
Definition: status.h:60