Normalize grpc_error_handle usage (#26240)

pull/26262/head
Esun Kim 4 years ago committed by GitHub
parent 049d4e5bb1
commit 770989b554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/ext/filters/client_idle/client_idle_filter.cc
  2. 8
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  3. 4
      src/core/ext/transport/chttp2/transport/parsing.cc
  4. 64
      src/core/ext/transport/inproc/inproc_transport.cc
  5. 9
      src/core/lib/iomgr/error.cc
  6. 2
      src/core/lib/iomgr/error.h
  7. 7
      src/core/lib/iomgr/tcp_server_custom.cc
  8. 4
      src/core/lib/transport/error_utils.cc
  9. 2
      src/core/lib/transport/transport_op_string.cc

@ -187,7 +187,7 @@ void ChannelData::StartTransportOp(grpc_channel_element* elem,
grpc_transport_op* op) { grpc_transport_op* op) {
ChannelData* chand = static_cast<ChannelData*>(elem->channel_data); ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
// Catch the disconnect_with_error transport op. // Catch the disconnect_with_error transport op.
if (op->disconnect_with_error != nullptr) { if (op->disconnect_with_error != GRPC_ERROR_NONE) {
// IncreaseCallCount() introduces a phony call and prevent the timer from // IncreaseCallCount() introduces a phony call and prevent the timer from
// being reset by other threads. // being reset by other threads.
chand->IncreaseCallCount(); chand->IncreaseCallCount();

@ -564,7 +564,7 @@ static void close_transport_locked(grpc_chttp2_transport* t,
GRPC_STATUS_UNAVAILABLE); GRPC_STATUS_UNAVAILABLE);
} }
if (t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE) { if (t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE) {
if (t->close_transport_on_writes_finished == nullptr) { if (t->close_transport_on_writes_finished == GRPC_ERROR_NONE) {
t->close_transport_on_writes_finished = t->close_transport_on_writes_finished =
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Delayed close due to in-progress write"); "Delayed close due to in-progress write");
@ -821,9 +821,9 @@ static void set_write_state(grpc_chttp2_transport* t,
// from peer while we had some pending writes) // from peer while we had some pending writes)
if (st == GRPC_CHTTP2_WRITE_STATE_IDLE) { if (st == GRPC_CHTTP2_WRITE_STATE_IDLE) {
grpc_core::ExecCtx::RunList(DEBUG_LOCATION, &t->run_after_write); grpc_core::ExecCtx::RunList(DEBUG_LOCATION, &t->run_after_write);
if (t->close_transport_on_writes_finished != nullptr) { if (t->close_transport_on_writes_finished != GRPC_ERROR_NONE) {
grpc_error_handle err = t->close_transport_on_writes_finished; grpc_error_handle err = t->close_transport_on_writes_finished;
t->close_transport_on_writes_finished = nullptr; t->close_transport_on_writes_finished = GRPC_ERROR_NONE;
close_transport_locked(t, err); close_transport_locked(t, err);
} }
} }
@ -1795,7 +1795,7 @@ static void perform_transport_op_locked(void* stream_op,
grpc_chttp2_transport* t = grpc_chttp2_transport* t =
static_cast<grpc_chttp2_transport*>(op->handler_private.extra_arg); static_cast<grpc_chttp2_transport*>(op->handler_private.extra_arg);
if (op->goaway_error) { if (op->goaway_error != GRPC_ERROR_NONE) {
send_goaway(t, op->goaway_error); send_goaway(t, op->goaway_error);
} }

@ -246,10 +246,10 @@ grpc_error_handle grpc_chttp2_perform_read(grpc_chttp2_transport* t,
t->incoming_frame_size -= static_cast<uint32_t>(end - cur); t->incoming_frame_size -= static_cast<uint32_t>(end - cur);
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
GPR_UNREACHABLE_CODE(return nullptr); GPR_UNREACHABLE_CODE(return GRPC_ERROR_NONE);
} }
GPR_UNREACHABLE_CODE(return nullptr); GPR_UNREACHABLE_CODE(return GRPC_ERROR_NONE);
} }
static grpc_error_handle init_frame_parser(grpc_chttp2_transport* t) { static grpc_error_handle init_frame_parser(grpc_chttp2_transport* t) {

@ -388,7 +388,8 @@ void complete_if_batch_end_locked(inproc_stream* s, grpc_error_handle error,
int is_rtm = static_cast<int>(op == s->recv_trailing_md_op); int is_rtm = static_cast<int>(op == s->recv_trailing_md_op);
if ((is_sm + is_stm + is_rim + is_rm + is_rtm) == 1) { if ((is_sm + is_stm + is_rim + is_rm + is_rtm) == 1) {
INPROC_LOG(GPR_INFO, "%s %p %p %p", msg, s, op, error); INPROC_LOG(GPR_INFO, "%s %p %p %s", msg, s, op,
grpc_error_std_string(error).c_str());
grpc_core::ExecCtx::Run(DEBUG_LOCATION, op->on_complete, grpc_core::ExecCtx::Run(DEBUG_LOCATION, op->on_complete,
GRPC_ERROR_REF(error)); GRPC_ERROR_REF(error));
} }
@ -468,8 +469,9 @@ void fail_helper_locked(inproc_stream* s, grpc_error_handle error) {
.trailing_metadata_available = true; .trailing_metadata_available = true;
} }
INPROC_LOG(GPR_INFO, INPROC_LOG(GPR_INFO,
"fail_helper %p scheduling initial-metadata-ready %p %p", s, "fail_helper %p scheduling initial-metadata-ready %s %s", s,
error, err); grpc_error_std_string(error).c_str(),
grpc_error_std_string(err).c_str());
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
s->recv_initial_md_op->payload->recv_initial_metadata s->recv_initial_md_op->payload->recv_initial_metadata
@ -483,8 +485,8 @@ void fail_helper_locked(inproc_stream* s, grpc_error_handle error) {
s->recv_initial_md_op = nullptr; s->recv_initial_md_op = nullptr;
} }
if (s->recv_message_op) { if (s->recv_message_op) {
INPROC_LOG(GPR_INFO, "fail_helper %p scheduling message-ready %p", s, INPROC_LOG(GPR_INFO, "fail_helper %p scheduling message-ready %s", s,
error); grpc_error_std_string(error).c_str());
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
s->recv_message_op->payload->recv_message.recv_message_ready, s->recv_message_op->payload->recv_message.recv_message_ready,
@ -508,15 +510,15 @@ void fail_helper_locked(inproc_stream* s, grpc_error_handle error) {
s->send_trailing_md_op = nullptr; s->send_trailing_md_op = nullptr;
} }
if (s->recv_trailing_md_op) { if (s->recv_trailing_md_op) {
INPROC_LOG(GPR_INFO, "fail_helper %p scheduling trailing-metadata-ready %p", INPROC_LOG(GPR_INFO, "fail_helper %p scheduling trailing-metadata-ready %s",
s, error); s, grpc_error_std_string(error).c_str());
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
s->recv_trailing_md_op->payload->recv_trailing_metadata s->recv_trailing_md_op->payload->recv_trailing_metadata
.recv_trailing_metadata_ready, .recv_trailing_metadata_ready,
GRPC_ERROR_REF(error)); GRPC_ERROR_REF(error));
INPROC_LOG(GPR_INFO, "fail_helper %p scheduling trailing-md-on-complete %p", INPROC_LOG(GPR_INFO, "fail_helper %p scheduling trailing-md-on-complete %s",
s, error); s, grpc_error_std_string(error).c_str());
complete_if_batch_end_locked( complete_if_batch_end_locked(
s, error, s->recv_trailing_md_op, s, error, s->recv_trailing_md_op,
"fail_helper scheduling recv-trailing-metadata-on-complete"); "fail_helper scheduling recv-trailing-metadata-on-complete");
@ -685,8 +687,8 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
INPROC_LOG( INPROC_LOG(
GPR_INFO, GPR_INFO,
"op_state_machine %p scheduling on_complete errors for already " "op_state_machine %p scheduling on_complete errors for already "
"recvd initial md %p", "recvd initial md %s",
s, new_err); s, grpc_error_std_string(new_err).c_str());
fail_helper_locked(s, GRPC_ERROR_REF(new_err)); fail_helper_locked(s, GRPC_ERROR_REF(new_err));
goto done; goto done;
} }
@ -710,8 +712,8 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
grpc_metadata_batch_clear(&s->to_read_initial_md); grpc_metadata_batch_clear(&s->to_read_initial_md);
s->to_read_initial_md_filled = false; s->to_read_initial_md_filled = false;
INPROC_LOG(GPR_INFO, INPROC_LOG(GPR_INFO,
"op_state_machine %p scheduling initial-metadata-ready %p", s, "op_state_machine %p scheduling initial-metadata-ready %s", s,
new_err); grpc_error_std_string(new_err).c_str());
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
s->recv_initial_md_op->payload->recv_initial_metadata s->recv_initial_md_op->payload->recv_initial_metadata
@ -724,8 +726,8 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
if (new_err != GRPC_ERROR_NONE) { if (new_err != GRPC_ERROR_NONE) {
INPROC_LOG(GPR_INFO, INPROC_LOG(GPR_INFO,
"op_state_machine %p scheduling on_complete errors2 %p", s, "op_state_machine %p scheduling on_complete errors2 %s", s,
new_err); grpc_error_std_string(new_err).c_str());
fail_helper_locked(s, GRPC_ERROR_REF(new_err)); fail_helper_locked(s, GRPC_ERROR_REF(new_err));
goto done; goto done;
} }
@ -753,8 +755,8 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
INPROC_LOG( INPROC_LOG(
GPR_INFO, GPR_INFO,
"op_state_machine %p scheduling on_complete errors for already " "op_state_machine %p scheduling on_complete errors for already "
"recvd trailing md %p", "recvd trailing md %s",
s, new_err); s, grpc_error_std_string(new_err).c_str());
fail_helper_locked(s, GRPC_ERROR_REF(new_err)); fail_helper_locked(s, GRPC_ERROR_REF(new_err));
goto done; goto done;
} }
@ -801,8 +803,8 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
// a final status, so don't mark this op complete) // a final status, so don't mark this op complete)
if (s->t->is_client || s->trailing_md_sent) { if (s->t->is_client || s->trailing_md_sent) {
INPROC_LOG(GPR_INFO, INPROC_LOG(GPR_INFO,
"op_state_machine %p scheduling trailing-md-on-complete %p", "op_state_machine %p scheduling trailing-md-on-complete %s",
s, new_err); s, grpc_error_std_string(new_err).c_str());
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
s->recv_trailing_md_op->payload->recv_trailing_metadata s->recv_trailing_md_op->payload->recv_trailing_metadata
@ -816,8 +818,8 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
} else { } else {
INPROC_LOG(GPR_INFO, INPROC_LOG(GPR_INFO,
"op_state_machine %p server needs to delay handling " "op_state_machine %p server needs to delay handling "
"trailing-md-on-complete %p", "trailing-md-on-complete %s",
s, new_err); s, grpc_error_std_string(new_err).c_str());
} }
} else if (!s->trailing_md_recvd) { } else if (!s->trailing_md_recvd) {
INPROC_LOG( INPROC_LOG(
@ -830,8 +832,8 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
// In this case, we don't care to receive the write-close from the client // In this case, we don't care to receive the write-close from the client
// because we have already sent status and the RPC is over as far as we // because we have already sent status and the RPC is over as far as we
// are concerned. // are concerned.
INPROC_LOG(GPR_INFO, "op_state_machine %p scheduling trailing-md-ready %p", INPROC_LOG(GPR_INFO, "op_state_machine %p scheduling trailing-md-ready %s",
s, new_err); s, grpc_error_std_string(new_err).c_str());
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
s->recv_trailing_md_op->payload->recv_trailing_metadata s->recv_trailing_md_op->payload->recv_trailing_metadata
@ -1091,8 +1093,8 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
} }
INPROC_LOG( INPROC_LOG(
GPR_INFO, GPR_INFO,
"perform_stream_op error %p scheduling initial-metadata-ready %p", "perform_stream_op error %p scheduling initial-metadata-ready %s",
s, error); s, grpc_error_std_string(error).c_str());
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
op->payload->recv_initial_metadata.recv_initial_metadata_ready, op->payload->recv_initial_metadata.recv_initial_metadata_ready,
@ -1101,8 +1103,8 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
if (op->recv_message) { if (op->recv_message) {
INPROC_LOG( INPROC_LOG(
GPR_INFO, GPR_INFO,
"perform_stream_op error %p scheduling recv message-ready %p", s, "perform_stream_op error %p scheduling recv message-ready %s", s,
error); grpc_error_std_string(error).c_str());
grpc_core::ExecCtx::Run(DEBUG_LOCATION, grpc_core::ExecCtx::Run(DEBUG_LOCATION,
op->payload->recv_message.recv_message_ready, op->payload->recv_message.recv_message_ready,
GRPC_ERROR_REF(error)); GRPC_ERROR_REF(error));
@ -1110,16 +1112,16 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
if (op->recv_trailing_metadata) { if (op->recv_trailing_metadata) {
INPROC_LOG( INPROC_LOG(
GPR_INFO, GPR_INFO,
"perform_stream_op error %p scheduling trailing-metadata-ready %p", "perform_stream_op error %p scheduling trailing-metadata-ready %s",
s, error); s, grpc_error_std_string(error).c_str());
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
op->payload->recv_trailing_metadata.recv_trailing_metadata_ready, op->payload->recv_trailing_metadata.recv_trailing_metadata_ready,
GRPC_ERROR_REF(error)); GRPC_ERROR_REF(error));
} }
} }
INPROC_LOG(GPR_INFO, "perform_stream_op %p scheduling on_complete %p", s, INPROC_LOG(GPR_INFO, "perform_stream_op %p scheduling on_complete %s", s,
error); grpc_error_std_string(error).c_str());
grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_complete, GRPC_ERROR_REF(error)); grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_complete, GRPC_ERROR_REF(error));
} }
gpr_mu_unlock(mu); gpr_mu_unlock(mu);

@ -59,7 +59,7 @@ absl::Status grpc_status_create(absl::StatusCode code, absl::string_view msg,
absl::Status s = StatusCreate(code, msg, location, {}); absl::Status s = StatusCreate(code, msg, location, {});
for (size_t i = 0; i < children_count; ++i) { for (size_t i = 0; i < children_count; ++i) {
if (!children[i].ok()) { if (!children[i].ok()) {
StatusAddChild(&s, children[i]); grpc_core::StatusAddChild(&s, children[i]);
} }
} }
return s; return s;
@ -73,10 +73,11 @@ absl::Status grpc_os_error(const grpc_core::DebugLocation& location, int err,
const char* call_name) { const char* call_name) {
absl::Status s = absl::Status s =
StatusCreate(absl::StatusCode::kUnknown, "OS Error", location, {}); StatusCreate(absl::StatusCode::kUnknown, "OS Error", location, {});
grpc_core::StatusSetInt(&s, grpc_core::StatusIntProperty::ERRNO, err); grpc_core::StatusSetInt(&s, grpc_core::StatusIntProperty::kErrorNo, err);
grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::OS_ERROR, grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::kOsError,
strerror(err)); strerror(err));
grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::SYSCALL, call_name); grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::kSyscall,
call_name);
return s; return s;
} }

@ -166,7 +166,7 @@ void grpc_enable_error_creation();
#define GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc) \ #define GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc) \
StatusCreate(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {}) StatusCreate(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {})
#define GRPC_ERROR_CREATE_FROM_STRING_VIEW(desc) \ #define GRPC_ERROR_CREATE_FROM_STRING_VIEW(desc) \
StatusCreate(ababsl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {}) StatusCreate(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {})
absl::Status grpc_status_create(absl::StatusCode code, absl::string_view msg, absl::Status grpc_status_create(absl::StatusCode code, absl::string_view msg,
const grpc_core::DebugLocation& location, const grpc_core::DebugLocation& location,

@ -362,10 +362,9 @@ static grpc_error_handle tcp_server_add_port(grpc_tcp_server* s,
for (sp = s->head; sp; sp = sp->next) { for (sp = s->head; sp; sp = sp->next) {
socket = sp->socket; socket = sp->socket;
sockname_temp.len = GRPC_MAX_SOCKADDR_SIZE; sockname_temp.len = GRPC_MAX_SOCKADDR_SIZE;
if (nullptr == grpc_custom_socket_vtable->getsockname( if (grpc_custom_socket_vtable->getsockname(
socket, socket, reinterpret_cast<grpc_sockaddr*>(&sockname_temp.addr),
reinterpret_cast<grpc_sockaddr*>(&sockname_temp.addr), reinterpret_cast<int*>(&sockname_temp.len)) == GRPC_ERROR_NONE) {
reinterpret_cast<int*>(&sockname_temp.len))) {
*port = grpc_sockaddr_get_port(&sockname_temp); *port = grpc_sockaddr_get_port(&sockname_temp);
if (*port > 0) { if (*port > 0) {
allocated_addr = static_cast<grpc_resolved_address*>( allocated_addr = static_cast<grpc_resolved_address*>(

@ -74,7 +74,7 @@ void grpc_error_get_status(grpc_error_handle error, grpc_millis deadline,
// until we find the first one that has a status code. // until we find the first one that has a status code.
grpc_error_handle found_error = grpc_error_handle found_error =
recursively_find_error_with_field(error, GRPC_ERROR_INT_GRPC_STATUS); recursively_find_error_with_field(error, GRPC_ERROR_INT_GRPC_STATUS);
if (found_error == nullptr) { if (found_error == GRPC_ERROR_NONE) {
/// If no grpc-status exists, retry through the tree to find a http2 error /// If no grpc-status exists, retry through the tree to find a http2 error
/// code /// code
found_error = found_error =
@ -83,7 +83,7 @@ void grpc_error_get_status(grpc_error_handle error, grpc_millis deadline,
// If we found an error with a status code above, use that; otherwise, // If we found an error with a status code above, use that; otherwise,
// fall back to using the parent error. // fall back to using the parent error.
if (found_error == nullptr) found_error = error; if (found_error == GRPC_ERROR_NONE) found_error = error;
grpc_status_code status = GRPC_STATUS_UNKNOWN; grpc_status_code status = GRPC_STATUS_UNKNOWN;
intptr_t integer; intptr_t integer;

@ -135,7 +135,7 @@ std::string grpc_transport_op_string(grpc_transport_op* op) {
" DISCONNECT:", grpc_error_std_string(op->disconnect_with_error))); " DISCONNECT:", grpc_error_std_string(op->disconnect_with_error)));
} }
if (op->goaway_error) { if (op->goaway_error != GRPC_ERROR_NONE) {
out.push_back(absl::StrCat(" SEND_GOAWAY:%s", out.push_back(absl::StrCat(" SEND_GOAWAY:%s",
grpc_error_std_string(op->goaway_error))); grpc_error_std_string(op->goaway_error)));
} }

Loading…
Cancel
Save