GRPC C++  1.39.1
status_helper.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2021 the 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 GRPC_CORE_LIB_GPRPP_STATUS_HELPER_H
20 #define GRPC_CORE_LIB_GPRPP_STATUS_HELPER_H
21 
23 
24 #include <vector>
25 
26 #include "absl/status/status.h"
27 #include "absl/time/time.h"
28 #include "absl/types/optional.h"
29 
31 
32 extern "C" {
33 struct google_rpc_Status;
34 struct upb_arena;
35 }
36 
37 namespace grpc_core {
38 
40 // TODO(veblush): Use camel-case names once migration to absl::Status is done.
41 enum class StatusIntProperty {
43  kErrorNo,
45  kFileLine,
48  kStreamId,
50  // TODO(veblush): Remove this after grpc_error is replaced with absl::Status
51  kRpcStatus,
54  kOffset,
56  kIndex,
58  kSize,
62  kTsiCode,
64  kWsaError,
66  kFd,
75 };
76 
78 // TODO(veblush): Use camel-case names once migration to absl::Status is done.
79 enum class StatusStrProperty {
83  kFile,
85  kOsError,
87  kSyscall,
93  kRawBytes,
95  kTsiError,
97  kFilename,
99  kKey,
101  kValue,
102 };
103 
105 enum class StatusTimeProperty {
107  kCreated,
108 };
109 
112  absl::StatusCode code, absl::string_view msg, const DebugLocation& location,
113  std::initializer_list<absl::Status> children) GRPC_MUST_USE_RESULT;
114 
116 void StatusSetInt(absl::Status* status, StatusIntProperty key, intptr_t value);
117 
119 absl::optional<intptr_t> StatusGetInt(
121 
124  absl::string_view value);
125 
127 absl::optional<std::string> StatusGetStr(
129 
132  absl::Time time);
133 
135 absl::optional<absl::Time> StatusGetTime(
137 
139 void StatusAddChild(absl::Status* status, absl::Status child);
140 
142 std::vector<absl::Status> StatusGetChildren(absl::Status status)
144 
150 std::string StatusToString(const absl::Status& status) GRPC_MUST_USE_RESULT;
151 
152 namespace internal {
153 
157  upb_arena* arena) GRPC_MUST_USE_RESULT;
158 
162 
164 static constexpr uintptr_t kOkStatusPtr = 0;
165 
169 uintptr_t StatusAllocPtr(absl::Status s);
170 
173 void StatusFreePtr(uintptr_t ptr);
174 
177 absl::Status StatusGetFromPtr(uintptr_t ptr);
178 
179 } // namespace internal
180 
181 } // namespace grpc_core
182 
183 #endif // GRPC_CORE_LIB_GPRPP_STATUS_HELPER_H
struct google_rpc_Status google_rpc_Status
Definition: status.upb.h:24
#define GRPC_MUST_USE_RESULT
Definition: port_platform.h:524
::google::protobuf::util::Status Status
Definition: config_protobuf.h:91
google_rpc_Status * StatusToProto(absl::Status status, upb_arena *arena)
Builds a upb message, google_rpc_Status from a status This is for internal implementation & test only...
Definition: status_helper.cc:333
uintptr_t StatusAllocPtr(absl::Status s)
Returns ptr where the given status is copied into.
Definition: status_helper.cc:381
absl::Status StatusFromProto(google_rpc_Status *msg)
Builds a status from a upb message, google_rpc_Status This is for internal implementation & test only...
Definition: status_helper.cc:364
void StatusFreePtr(uintptr_t ptr)
Frees the allocated status at ptr.
Definition: status_helper.cc:395
absl::Status StatusGetFromPtr(uintptr_t ptr)
Get the status from ptr.
Definition: status_helper.cc:400
Round Robin Policy.
Definition: backend_metric.cc:26
void StatusSetInt(absl::Status *status, StatusIntProperty key, intptr_t value)
Sets the int property to the status.
Definition: status_helper.cc:178
std::vector< absl::Status > StatusGetChildren(absl::Status status)
Returns all children status from a status.
Definition: status_helper.cc:261
absl::optional< std::string > StatusGetStr(const absl::Status &status, StatusStrProperty key)
Gets the str property from the status.
Definition: status_helper.cc:208
void StatusSetStr(absl::Status *status, StatusStrProperty key, absl::string_view value)
Sets the str property to the status.
Definition: status_helper.cc:203
absl::optional< absl::Time > StatusGetTime(const absl::Status &status, StatusTimeProperty key)
Gets the time property from the status.
Definition: status_helper.cc:225
absl::optional< intptr_t > StatusGetInt(const absl::Status &status, StatusIntProperty key)
Gets the int property from the status.
Definition: status_helper.cc:183
StatusStrProperty
This enum should have the same value of grpc_error_strs.
Definition: status_helper.h:79
@ kFile
source file in which this error occurred
@ kKey
key associated with the error
@ kFilename
filename that we were trying to read/write when this error occurred
@ kDescription
top-level textual description of this error
@ kGrpcMessage
grpc status message associated with this error
@ kValue
value associated with the error
@ kRawBytes
hex dump (or similar) with the data that generated this error
@ kSyscall
syscall that generated this error
@ kOsError
operating system description of this error
@ kTargetAddress
peer that we were trying to communicate when this error occurred
@ kTsiError
tsi error string associated with this error
StatusTimeProperty
This enum should have the same value of grpc_error_times.
Definition: status_helper.h:105
@ kCreated
timestamp of error creation
std::string StatusToString(const absl::Status &status)
Returns a string representation from status Error status will be like STATUS[:MESSAGE] [{PAYLOADS[,...
Definition: status_helper.cc:267
void StatusAddChild(absl::Status *status, absl::Status child)
Adds a child status to status.
Definition: status_helper.cc:241
void StatusSetTime(absl::Status *status, StatusTimeProperty key, absl::Time time)
Sets the time property to the status.
Definition: status_helper.cc:218
absl::Status StatusCreate(absl::StatusCode code, absl::string_view msg, const DebugLocation &location, std::initializer_list< absl::Status > children)
Creates a status with given additional information.
Definition: status_helper.cc:159
StatusIntProperty
This enum should have the same value of grpc_error_ints.
Definition: status_helper.h:41
@ kLbPolicyDrop
LB policy drop.
@ kOffset
offset into some binary blob (usually represented by RAW_BYTES) where the error occurred
@ kStreamId
stream identifier: for errors that are associated with an individual wire stream
@ ChannelConnectivityState
channel connectivity state associated with the error
@ kSize
context sensitive size associated with the error
@ kHttp2Error
http2 error code associated with the error (see the HTTP2 RFC)
@ kHttpStatus
HTTP status (i.e. 404)
@ kFileLine
LINE from the call site creating the error
@ kErrorNo
'errno' from the operating system
@ kFd
File descriptor associated with this error.
@ kWsaError
WSAGetLastError() reported when this error occurred.
@ kIndex
context sensitive index associated with the error
@ kOccurredDuringWrite
chttp2: did the error occur while a write was in progress
@ kTsiCode
TSI status code associated with the error.
@ kRpcStatus
grpc status code representing this error
StatusCode
Definition: status_code_enum.h:24
upb_arena * arena
Definition: xds_api.cc:909