Simplified GRPC_ERROR_CREATE macros (#31222)

* Simplified GRPC_ERROR_CREATE macros

* Code migration
pull/31058/head^2
Esun Kim 2 years ago committed by GitHub
parent cf917bc365
commit 3c96517fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/core/ext/filters/channel_idle/channel_idle_filter.cc
  2. 6
      src/core/ext/filters/client_channel/channel_connectivity.cc
  3. 13
      src/core/ext/filters/client_channel/client_channel.cc
  4. 2
      src/core/ext/filters/client_channel/connector.h
  5. 4
      src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc
  6. 16
      src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
  7. 2
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc
  8. 29
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc
  9. 14
      src/core/ext/filters/client_channel/resolver_result_parsing.cc
  10. 22
      src/core/ext/filters/client_channel/retry_filter.cc
  11. 62
      src/core/ext/filters/client_channel/retry_service_config.cc
  12. 6
      src/core/ext/filters/deadline/deadline_filter.cc
  13. 10
      src/core/ext/filters/fault_injection/service_config_parser.cc
  14. 4
      src/core/ext/filters/http/message_compress/message_decompress_filter.cc
  15. 12
      src/core/ext/filters/message_size/message_size_filter.cc
  16. 9
      src/core/ext/filters/rbac/rbac_filter.cc
  17. 21
      src/core/ext/filters/rbac/rbac_service_config_parser.cc
  18. 10
      src/core/ext/transport/binder/transport/binder_transport.cc
  19. 7
      src/core/ext/transport/chttp2/client/chttp2_connector.cc
  20. 39
      src/core/ext/transport/chttp2/server/chttp2_server.cc
  21. 103
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  22. 8
      src/core/ext/transport/chttp2/transport/frame_data.cc
  23. 5
      src/core/ext/transport/chttp2/transport/frame_goaway.cc
  24. 2
      src/core/ext/transport/chttp2/transport/frame_ping.cc
  25. 4
      src/core/ext/transport/chttp2/transport/frame_rst_stream.cc
  26. 11
      src/core/ext/transport/chttp2/transport/frame_settings.cc
  27. 4
      src/core/ext/transport/chttp2/transport/frame_window_update.cc
  28. 30
      src/core/ext/transport/chttp2/transport/hpack_parser.cc
  29. 4
      src/core/ext/transport/chttp2/transport/hpack_parser_table.cc
  30. 20
      src/core/ext/transport/chttp2/transport/parsing.cc
  31. 2
      src/core/ext/transport/cronet/transport/cronet_transport.cc
  32. 19
      src/core/ext/transport/inproc/inproc_transport.cc
  33. 7
      src/core/ext/xds/file_watcher_certificate_provider_factory.cc
  34. 15
      src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc
  35. 8
      src/core/ext/xds/xds_certificate_provider.cc
  36. 2
      src/core/ext/xds/xds_listener.cc
  37. 19
      src/core/ext/xds/xds_server_config_fetcher.cc
  38. 4
      src/core/lib/address_utils/parse_address.cc
  39. 3
      src/core/lib/channel/connected_channel.cc
  40. 12
      src/core/lib/channel/promise_based_filter.cc
  41. 40
      src/core/lib/http/httpcli.cc
  42. 4
      src/core/lib/http/httpcli_security_connector.cc
  43. 83
      src/core/lib/http/parser.cc
  44. 7
      src/core/lib/iomgr/endpoint_cfstream.cc
  45. 38
      src/core/lib/iomgr/error.h
  46. 5
      src/core/lib/iomgr/ev_epoll1_linux.cc
  47. 13
      src/core/lib/iomgr/ev_poll_posix.cc
  48. 7
      src/core/lib/iomgr/load_file.cc
  49. 12
      src/core/lib/iomgr/lockfree_event.cc
  50. 2
      src/core/lib/iomgr/python_util.h
  51. 15
      src/core/lib/iomgr/resolve_address_posix.cc
  52. 7
      src/core/lib/iomgr/resolve_address_windows.cc
  53. 13
      src/core/lib/iomgr/socket_utils_common_posix.cc
  54. 6
      src/core/lib/iomgr/tcp_client_cfstream.cc
  55. 6
      src/core/lib/iomgr/tcp_client_posix.cc
  56. 7
      src/core/lib/iomgr/tcp_client_windows.cc
  57. 13
      src/core/lib/iomgr/tcp_posix.cc
  58. 12
      src/core/lib/iomgr/tcp_server_posix.cc
  59. 9
      src/core/lib/iomgr/tcp_server_utils_posix_common.cc
  60. 13
      src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc
  61. 2
      src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc
  62. 9
      src/core/lib/iomgr/tcp_server_windows.cc
  63. 16
      src/core/lib/iomgr/tcp_windows.cc
  64. 10
      src/core/lib/iomgr/timer_generic.cc
  65. 10
      src/core/lib/json/json_util.cc
  66. 8
      src/core/lib/json/json_util.h
  67. 65
      src/core/lib/security/credentials/external/aws_external_account_credentials.cc
  68. 6
      src/core/lib/security/credentials/external/aws_request_signer.cc
  69. 61
      src/core/lib/security/credentials/external/external_account_credentials.cc
  70. 25
      src/core/lib/security/credentials/external/file_external_account_credentials.cc
  71. 34
      src/core/lib/security/credentials/external/url_external_account_credentials.cc
  72. 22
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  73. 18
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  74. 23
      src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc
  75. 3
      src/core/lib/security/security_connector/alts/alts_security_connector.cc
  76. 13
      src/core/lib/security/security_connector/fake/fake_security_connector.cc
  77. 10
      src/core/lib/security/security_connector/local/local_security_connector.cc
  78. 8
      src/core/lib/security/security_connector/ssl/ssl_security_connector.cc
  79. 7
      src/core/lib/security/security_connector/ssl_utils.cc
  80. 4
      src/core/lib/security/security_connector/tls/tls_security_connector.cc
  81. 12
      src/core/lib/security/transport/secure_endpoint.cc
  82. 36
      src/core/lib/security/transport/security_handshaker.cc
  83. 6
      src/core/lib/security/transport/server_auth_filter.cc
  84. 7
      src/core/lib/security/util/json_util.cc
  85. 18
      src/core/lib/surface/call.cc
  86. 3
      src/core/lib/surface/channel.cc
  87. 4
      src/core/lib/surface/lame_client.cc
  88. 24
      src/core/lib/surface/server.cc
  89. 11
      src/core/lib/surface/validate_metadata.cc
  90. 7
      src/core/lib/transport/error_utils.cc
  91. 4
      src/core/lib/transport/handshaker.cc
  92. 7
      src/core/lib/transport/http_connect_handshaker.cc
  93. 8
      src/core/lib/transport/tcp_connect_handshaker.cc
  94. 3
      test/core/bad_client/bad_client.cc
  95. 3
      test/core/end2end/bad_server_response_test.cc
  96. 6
      test/core/end2end/fixtures/http_proxy_fixture.cc
  97. 11
      test/core/end2end/fuzzers/api_fuzzer.cc
  98. 2
      test/core/end2end/goaway_server_test.cc
  99. 2
      test/core/end2end/tests/filter_causes_close.cc
  100. 8
      test/core/end2end/tests/filter_init_fails.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -187,7 +187,7 @@ void MaxAgeFilter::PostInit() {
auto* channel_stack = static_cast<grpc_channel_stack*>(arg); auto* channel_stack = static_cast<grpc_channel_stack*>(arg);
grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_transport_op* op = grpc_make_transport_op(nullptr);
op->goaway_error = grpc_error_set_int( op->goaway_error = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("max_age"), GRPC_ERROR_CREATE("max_age"),
StatusIntProperty::kHttp2Error, GRPC_HTTP2_NO_ERROR); StatusIntProperty::kHttp2Error, GRPC_HTTP2_NO_ERROR);
grpc_channel_element* elem = grpc_channel_element* elem =
grpc_channel_stack_element(channel_stack, 0); grpc_channel_stack_element(channel_stack, 0);
@ -278,7 +278,7 @@ void ChannelIdleFilter::StartIdleTimer() {
void ChannelIdleFilter::CloseChannel() { void ChannelIdleFilter::CloseChannel() {
auto* op = grpc_make_transport_op(nullptr); auto* op = grpc_make_transport_op(nullptr);
op->disconnect_with_error = grpc_error_set_int( op->disconnect_with_error = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("enter idle"), GRPC_ERROR_CREATE("enter idle"),
StatusIntProperty::ChannelConnectivityState, GRPC_CHANNEL_IDLE); StatusIntProperty::ChannelConnectivityState, GRPC_CHANNEL_IDLE);
// Pass the transport op down to the channel stack. // Pass the transport op down to the channel stack.
auto* elem = grpc_channel_stack_element(channel_stack_, 0); auto* elem = grpc_channel_stack_element(channel_stack_, 0);

@ -195,9 +195,9 @@ class StateWatcher : public DualRefCounted<StateWatcher> {
void Orphan() override { void Orphan() override {
WeakRef().release(); // Take a weak ref until completion is finished. WeakRef().release(); // Take a weak ref until completion is finished.
grpc_error_handle error = grpc_error_handle error =
timer_fired_ ? GRPC_ERROR_CREATE_FROM_STATIC_STRING( timer_fired_
"Timed out waiting for connection state change") ? GRPC_ERROR_CREATE("Timed out waiting for connection state change")
: absl::OkStatus(); : absl::OkStatus();
grpc_cq_end_op(cq_, tag_, error, FinishedCompletion, this, grpc_cq_end_op(cq_, tag_, error, FinishedCompletion, this,
&completion_storage_); &completion_storage_);
} }

@ -996,7 +996,7 @@ ClientChannel::ClientChannel(grpc_channel_element_args* args,
grpc_client_channel_start_backup_polling(interested_parties_); grpc_client_channel_start_backup_polling(interested_parties_);
// Check client channel factory. // Check client channel factory.
if (client_channel_factory_ == nullptr) { if (client_channel_factory_ == nullptr) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"Missing client channel factory in args for client channel filter"); "Missing client channel factory in args for client channel filter");
return; return;
} }
@ -1017,7 +1017,7 @@ ClientChannel::ClientChannel(grpc_channel_element_args* args,
absl::optional<std::string> server_uri = absl::optional<std::string> server_uri =
channel_args_.GetOwnedString(GRPC_ARG_SERVER_URI); channel_args_.GetOwnedString(GRPC_ARG_SERVER_URI);
if (!server_uri.has_value()) { if (!server_uri.has_value()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"target URI channel arg missing or wrong type in client channel " "target URI channel arg missing or wrong type in client channel "
"filter"); "filter");
return; return;
@ -1030,7 +1030,7 @@ ClientChannel::ClientChannel(grpc_channel_element_args* args,
// resolver creation will succeed later. // resolver creation will succeed later.
if (!CoreConfiguration::Get().resolver_registry().IsValidTarget( if (!CoreConfiguration::Get().resolver_registry().IsValidTarget(
uri_to_resolve_)) { uri_to_resolve_)) {
*error = GRPC_ERROR_CREATE_FROM_CPP_STRING( *error = GRPC_ERROR_CREATE(
absl::StrCat("the target uri is not valid: ", uri_to_resolve_)); absl::StrCat("the target uri is not valid: ", uri_to_resolve_));
return; return;
} }
@ -1628,7 +1628,7 @@ T HandlePickResult(
grpc_error_handle ClientChannel::DoPingLocked(grpc_transport_op* op) { grpc_error_handle ClientChannel::DoPingLocked(grpc_transport_op* op) {
if (state_tracker_.state() != GRPC_CHANNEL_READY) { if (state_tracker_.state() != GRPC_CHANNEL_READY) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("channel not connected"); return GRPC_ERROR_CREATE("channel not connected");
} }
LoadBalancingPolicy::PickResult result; LoadBalancingPolicy::PickResult result;
{ {
@ -1645,8 +1645,7 @@ grpc_error_handle ClientChannel::DoPingLocked(grpc_transport_op* op) {
RefCountedPtr<ConnectedSubchannel> connected_subchannel = RefCountedPtr<ConnectedSubchannel> connected_subchannel =
subchannel->connected_subchannel(); subchannel->connected_subchannel();
if (connected_subchannel == nullptr) { if (connected_subchannel == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("LB pick for ping not connected");
"LB pick for ping not connected");
} }
connected_subchannel->Ping(op->send_ping.on_initiate, connected_subchannel->Ping(op->send_ping.on_initiate,
op->send_ping.on_ack); op->send_ping.on_ack);
@ -1654,7 +1653,7 @@ grpc_error_handle ClientChannel::DoPingLocked(grpc_transport_op* op) {
}, },
// Queue pick. // Queue pick.
[](LoadBalancingPolicy::PickResult::Queue* /*queue_pick*/) { [](LoadBalancingPolicy::PickResult::Queue* /*queue_pick*/) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("LB picker queued call"); return GRPC_ERROR_CREATE("LB picker queued call");
}, },
// Fail pick. // Fail pick.
[](LoadBalancingPolicy::PickResult::Fail* fail_pick) { [](LoadBalancingPolicy::PickResult::Fail* fail_pick) {

@ -74,7 +74,7 @@ class SubchannelConnector : public InternallyRefCounted<SubchannelConnector> {
virtual void Shutdown(grpc_error_handle error) = 0; virtual void Shutdown(grpc_error_handle error) = 0;
void Orphan() override { void Orphan() override {
Shutdown(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Subchannel disconnected")); Shutdown(GRPC_ERROR_CREATE("Subchannel disconnected"));
Unref(); Unref();
} }
}; };

@ -95,7 +95,7 @@ class BinderResolverFactory : public ResolverFactory {
absl::string_view path, grpc_resolved_address* resolved_addr) { absl::string_view path, grpc_resolved_address* resolved_addr) {
path = absl::StripPrefix(path, "/"); path = absl::StripPrefix(path, "/");
if (path.empty()) { if (path.empty()) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING("path is empty"); return GRPC_ERROR_CREATE("path is empty");
} }
// Store parsed path in a unix socket so it can be reinterpreted as // Store parsed path in a unix socket so it can be reinterpreted as
// sockaddr. An invalid address family (AF_MAX) is set to make sure it won't // sockaddr. An invalid address family (AF_MAX) is set to make sure it won't
@ -107,7 +107,7 @@ class BinderResolverFactory : public ResolverFactory {
static_assert(sizeof(un->sun_path) >= 101, static_assert(sizeof(un->sun_path) >= 101,
"unix socket path size is unexpectedly short"); "unix socket path size is unexpectedly short");
if (path.size() + 1 > sizeof(un->sun_path)) { if (path.size() + 1 > sizeof(un->sun_path)) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrCat(path, " is too long to be handled")); absl::StrCat(path, " is too long to be handled"));
} }
// `un` has already be set to zero, no need to append null after the string // `un` has already be set to zero, no need to append null after the string

@ -259,7 +259,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
return ""; return "";
} }
if (json->type() != Json::Type::ARRAY) { if (json->type() != Json::Type::ARRAY) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"Service Config Choices, error: should be of type array"); "Service Config Choices, error: should be of type array");
return ""; return "";
} }
@ -267,7 +267,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
std::vector<grpc_error_handle> error_list; std::vector<grpc_error_handle> error_list;
for (const Json& choice : json->array_value()) { for (const Json& choice : json->array_value()) {
if (choice.type() != Json::Type::OBJECT) { if (choice.type() != Json::Type::OBJECT) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"Service Config Choice, error: should be of type object")); "Service Config Choice, error: should be of type object"));
continue; continue;
} }
@ -275,7 +275,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
auto it = choice.object_value().find("clientLanguage"); auto it = choice.object_value().find("clientLanguage");
if (it != choice.object_value().end()) { if (it != choice.object_value().end()) {
if (it->second.type() != Json::Type::ARRAY) { if (it->second.type() != Json::Type::ARRAY) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:clientLanguage error:should be of type array")); "field:clientLanguage error:should be of type array"));
} else if (!ValueInJsonArray(it->second.array_value(), "c++")) { } else if (!ValueInJsonArray(it->second.array_value(), "c++")) {
continue; continue;
@ -285,7 +285,7 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
it = choice.object_value().find("clientHostname"); it = choice.object_value().find("clientHostname");
if (it != choice.object_value().end()) { if (it != choice.object_value().end()) {
if (it->second.type() != Json::Type::ARRAY) { if (it->second.type() != Json::Type::ARRAY) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:clientHostname error:should be of type array")); "field:clientHostname error:should be of type array"));
} else { } else {
char* hostname = grpc_gethostname(); char* hostname = grpc_gethostname();
@ -299,13 +299,13 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
it = choice.object_value().find("percentage"); it = choice.object_value().find("percentage");
if (it != choice.object_value().end()) { if (it != choice.object_value().end()) {
if (it->second.type() != Json::Type::NUMBER) { if (it->second.type() != Json::Type::NUMBER) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:percentage error:should be of type number")); "field:percentage error:should be of type number"));
} else { } else {
int random_pct = rand() % 100; int random_pct = rand() % 100;
int percentage; int percentage;
if (sscanf(it->second.string_value().c_str(), "%d", &percentage) != 1) { if (sscanf(it->second.string_value().c_str(), "%d", &percentage) != 1) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:percentage error:should be of type integer")); "field:percentage error:should be of type integer"));
} else if (random_pct > percentage || percentage == 0) { } else if (random_pct > percentage || percentage == 0) {
continue; continue;
@ -315,10 +315,10 @@ std::string ChooseServiceConfig(char* service_config_choice_json,
// Found service config. // Found service config.
it = choice.object_value().find("serviceConfig"); it = choice.object_value().find("serviceConfig");
if (it == choice.object_value().end()) { if (it == choice.object_value().end()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:serviceConfig error:required field missing")); "field:serviceConfig error:required field missing"));
} else if (it->second.type() != Json::Type::OBJECT) { } else if (it->second.type() != Json::Type::OBJECT) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:serviceConfig error:should be of type object")); "field:serviceConfig error:should be of type object"));
} else if (service_config == nullptr) { } else if (service_config == nullptr) {
service_config = &it->second; service_config = &it->second;

@ -794,7 +794,7 @@ class SockToPolledFdMap {
// If a gRPC polled fd has not made it in to the driver's list yet, then // If a gRPC polled fd has not made it in to the driver's list yet, then
// the driver has not and will never see this socket. // the driver has not and will never see this socket.
if (!polled_fd->gotten_into_driver_list()) { if (!polled_fd->gotten_into_driver_list()) {
polled_fd->ShutdownLocked(GRPC_ERROR_CREATE_FROM_STATIC_STRING( polled_fd->ShutdownLocked(GRPC_ERROR_CREATE(
"Shut down c-ares fd before without it ever having made it into the " "Shut down c-ares fd before without it ever having made it into the "
"driver's list")); "driver's list"));
} }

@ -225,8 +225,7 @@ static void fd_node_shutdown_locked(fd_node* fdn, const char* reason)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) { ABSL_EXCLUSIVE_LOCKS_REQUIRED(&grpc_ares_request::mu) {
if (!fdn->already_shutdown) { if (!fdn->already_shutdown) {
fdn->already_shutdown = true; fdn->already_shutdown = true;
fdn->grpc_polled_fd->ShutdownLocked( fdn->grpc_polled_fd->ShutdownLocked(GRPC_ERROR_CREATE(reason));
GRPC_ERROR_CREATE_FROM_STATIC_STRING(reason));
} }
} }
@ -527,7 +526,7 @@ grpc_error_handle grpc_ares_ev_driver_create_locked(
grpc_ares_test_only_inject_config((*ev_driver)->channel); grpc_ares_test_only_inject_config((*ev_driver)->channel);
GRPC_CARES_TRACE_LOG("request:%p grpc_ares_ev_driver_create_locked", request); GRPC_CARES_TRACE_LOG("request:%p grpc_ares_ev_driver_create_locked", request);
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
grpc_error_handle err = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( grpc_error_handle err = GRPC_ERROR_CREATE(absl::StrCat(
"Failed to init ares channel. C-ares error: ", ares_strerror(status))); "Failed to init ares channel. C-ares error: ", ares_strerror(status)));
delete *ev_driver; delete *ev_driver;
return err; return err;
@ -709,7 +708,7 @@ static void on_hostbyname_done_locked(void* arg, int status, int /*timeouts*/,
hr->qtype, hr->host, hr->is_balancer, ares_strerror(status)); hr->qtype, hr->host, hr->is_balancer, ares_strerror(status));
GRPC_CARES_TRACE_LOG("request:%p on_hostbyname_done_locked: %s", r, GRPC_CARES_TRACE_LOG("request:%p on_hostbyname_done_locked: %s", r,
error_msg.c_str()); error_msg.c_str());
grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING(error_msg); grpc_error_handle error = GRPC_ERROR_CREATE(error_msg);
r->error = grpc_error_add_child(error, r->error); r->error = grpc_error_add_child(error, r->error);
} }
destroy_hostbyname_request_locked(hr); destroy_hostbyname_request_locked(hr);
@ -756,7 +755,7 @@ static void on_srv_query_done_locked(void* arg, int status, int /*timeouts*/,
ares_strerror(status)); ares_strerror(status));
GRPC_CARES_TRACE_LOG("request:%p on_srv_query_done_locked: %s", r, GRPC_CARES_TRACE_LOG("request:%p on_srv_query_done_locked: %s", r,
error_msg.c_str()); error_msg.c_str());
grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING(error_msg); grpc_error_handle error = GRPC_ERROR_CREATE(error_msg);
r->error = grpc_error_add_child(error, r->error); r->error = grpc_error_add_child(error, r->error);
} }
delete q; delete q;
@ -819,7 +818,7 @@ fail:
q->name(), ares_strerror(status)); q->name(), ares_strerror(status));
GRPC_CARES_TRACE_LOG("request:%p on_txt_done_locked %s", r, GRPC_CARES_TRACE_LOG("request:%p on_txt_done_locked %s", r,
error_msg.c_str()); error_msg.c_str());
error = GRPC_ERROR_CREATE_FROM_CPP_STRING(error_msg); error = GRPC_ERROR_CREATE(error_msg);
r->error = grpc_error_add_child(error, r->error); r->error = grpc_error_add_child(error, r->error);
} }
@ -847,13 +846,13 @@ grpc_error_handle set_request_dns_server(grpc_ares_request* r,
r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr); r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr);
r->dns_server_addr.udp_port = grpc_sockaddr_get_port(&addr); r->dns_server_addr.udp_port = grpc_sockaddr_get_port(&addr);
} else { } else {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrCat("cannot parse authority ", dns_server)); absl::StrCat("cannot parse authority ", dns_server));
} }
int status = int status =
ares_set_servers_ports(r->ev_driver->channel, &r->dns_server_addr); ares_set_servers_ports(r->ev_driver->channel, &r->dns_server_addr);
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( return GRPC_ERROR_CREATE(absl::StrCat(
"C-ares status is not ARES_SUCCESS: ", ares_strerror(status))); "C-ares status is not ARES_SUCCESS: ", ares_strerror(status)));
} }
} }
@ -871,15 +870,15 @@ grpc_error_handle grpc_dns_lookup_ares_continued(
/* parse name, splitting it into host and port parts */ /* parse name, splitting it into host and port parts */
grpc_core::SplitHostPort(name, host, port); grpc_core::SplitHostPort(name, host, port);
if (host->empty()) { if (host->empty()) {
error = grpc_error_set_str( error =
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"), grpc_error_set_str(GRPC_ERROR_CREATE("unparseable host:port"),
grpc_core::StatusStrProperty::kTargetAddress, name); grpc_core::StatusStrProperty::kTargetAddress, name);
return error; return error;
} else if (check_port && port->empty()) { } else if (check_port && port->empty()) {
if (default_port == nullptr || strlen(default_port) == 0) { if (default_port == nullptr || strlen(default_port) == 0) {
error = grpc_error_set_str( error = grpc_error_set_str(GRPC_ERROR_CREATE("no port in name"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("no port in name"), grpc_core::StatusStrProperty::kTargetAddress,
grpc_core::StatusStrProperty::kTargetAddress, name); name);
return error; return error;
} }
*port = default_port; *port = default_port;
@ -1190,7 +1189,7 @@ void (*grpc_cancel_ares_request)(grpc_ares_request* r) =
grpc_error_handle grpc_ares_init(void) { grpc_error_handle grpc_ares_init(void) {
int status = ares_library_init(ARES_LIB_INIT_ALL); int status = ares_library_init(ARES_LIB_INIT_ALL);
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrCat("ares_library_init failed: ", ares_strerror(status))); absl::StrCat("ares_library_init failed: ", ares_strerror(status)));
} }
return absl::OkStatus(); return absl::OkStatus();

@ -58,7 +58,7 @@ absl::optional<std::string> ParseHealthCheckConfig(const Json& field,
grpc_error_handle* error) { grpc_error_handle* error) {
GPR_DEBUG_ASSERT(error != nullptr && error->ok()); GPR_DEBUG_ASSERT(error != nullptr && error->ok());
if (field.type() != Json::Type::OBJECT) { if (field.type() != Json::Type::OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"field:healthCheckConfig error:should be of type object"); "field:healthCheckConfig error:should be of type object");
return absl::nullopt; return absl::nullopt;
} }
@ -67,7 +67,7 @@ absl::optional<std::string> ParseHealthCheckConfig(const Json& field,
auto it = field.object_value().find("serviceName"); auto it = field.object_value().find("serviceName");
if (it != field.object_value().end()) { if (it != field.object_value().end()) {
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:serviceName error:should be of type string")); "field:serviceName error:should be of type string"));
} else { } else {
service_name = it->second.string_value(); service_name = it->second.string_value();
@ -92,7 +92,7 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const ChannelArgs& /*args*/,
if (it != json.object_value().end()) { if (it != json.object_value().end()) {
auto config = lb_policy_registry.ParseLoadBalancingConfig(it->second); auto config = lb_policy_registry.ParseLoadBalancingConfig(it->second);
if (!config.ok()) { if (!config.ok()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( error_list.push_back(GRPC_ERROR_CREATE(absl::StrCat(
"field:loadBalancingConfig error:", config.status().message()))); "field:loadBalancingConfig error:", config.status().message())));
} else { } else {
parsed_lb_config = std::move(*config); parsed_lb_config = std::move(*config);
@ -103,7 +103,7 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const ChannelArgs& /*args*/,
it = json.object_value().find("loadBalancingPolicy"); it = json.object_value().find("loadBalancingPolicy");
if (it != json.object_value().end()) { if (it != json.object_value().end()) {
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:loadBalancingPolicy error:type should be string")); "field:loadBalancingPolicy error:type should be string"));
} else { } else {
lb_policy_name = it->second.string_value(); lb_policy_name = it->second.string_value();
@ -113,10 +113,10 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const ChannelArgs& /*args*/,
bool requires_config = false; bool requires_config = false;
if (!lb_policy_registry.LoadBalancingPolicyExists(lb_policy_name.c_str(), if (!lb_policy_registry.LoadBalancingPolicyExists(lb_policy_name.c_str(),
&requires_config)) { &requires_config)) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:loadBalancingPolicy error:Unknown lb policy")); "field:loadBalancingPolicy error:Unknown lb policy"));
} else if (requires_config) { } else if (requires_config) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list.push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:loadBalancingPolicy error:", lb_policy_name, absl::StrCat("field:loadBalancingPolicy error:", lb_policy_name,
" requires a config. Please use loadBalancingConfig " " requires a config. Please use loadBalancingConfig "
"instead."))); "instead.")));
@ -160,7 +160,7 @@ ClientChannelServiceConfigParser::ParsePerMethodParams(
} else if (it->second.type() == Json::Type::JSON_FALSE) { } else if (it->second.type() == Json::Type::JSON_FALSE) {
wait_for_ready.emplace(false); wait_for_ready.emplace(false);
} else { } else {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:waitForReady error:Type should be true/false")); "field:waitForReady error:Type should be true/false"));
} }
} }

@ -192,15 +192,15 @@ class RetryFilter {
const char* server_uri = const char* server_uri =
grpc_channel_args_find_string(args, GRPC_ARG_SERVER_URI); grpc_channel_args_find_string(args, GRPC_ARG_SERVER_URI);
if (server_uri == nullptr) { if (server_uri == nullptr) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"server URI channel arg missing or wrong type in client channel " "server URI channel arg missing or wrong type in client channel "
"filter"); "filter");
return; return;
} }
absl::StatusOr<URI> uri = URI::Parse(server_uri); absl::StatusOr<URI> uri = URI::Parse(server_uri);
if (!uri.ok() || uri->path().empty()) { if (!uri.ok() || uri->path().empty()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error =
"could not extract server name from target URI"); GRPC_ERROR_CREATE("could not extract server name from target URI");
return; return;
} }
std::string server_name(absl::StripPrefix(uri->path(), "/")); std::string server_name(absl::StripPrefix(uri->path(), "/"));
@ -1281,10 +1281,9 @@ void RetryFilter::CallData::CallAttempt::OnPerAttemptRecvTimerLocked(
// TODO(roth): When implementing hedging, we should not cancel the // TODO(roth): When implementing hedging, we should not cancel the
// current attempt. // current attempt.
call_attempt->MaybeAddBatchForCancelOp( call_attempt->MaybeAddBatchForCancelOp(
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( grpc_error_set_int(
"retry perAttemptRecvTimeout exceeded"), GRPC_ERROR_CREATE("retry perAttemptRecvTimeout exceeded"),
StatusIntProperty::kRpcStatus, StatusIntProperty::kRpcStatus, GRPC_STATUS_CANCELLED),
GRPC_STATUS_CANCELLED),
&closures); &closures);
// Check whether we should retry. // Check whether we should retry.
if (call_attempt->ShouldRetry(/*status=*/absl::nullopt, if (call_attempt->ShouldRetry(/*status=*/absl::nullopt,
@ -1781,11 +1780,10 @@ void RetryFilter::CallData::CallAttempt::BatchData::RecvTrailingMetadataReady(
CallCombinerClosureList closures; CallCombinerClosureList closures;
// Cancel call attempt. // Cancel call attempt.
call_attempt->MaybeAddBatchForCancelOp( call_attempt->MaybeAddBatchForCancelOp(
error.ok() error.ok() ? grpc_error_set_int(
? grpc_error_set_int( GRPC_ERROR_CREATE("call attempt failed"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("call attempt failed"), StatusIntProperty::kRpcStatus, GRPC_STATUS_CANCELLED)
StatusIntProperty::kRpcStatus, GRPC_STATUS_CANCELLED) : error,
: error,
&closures); &closures);
// For transparent retries, add a closure to immediately start a new // For transparent retries, add a closure to immediately start a new
// call attempt. // call attempt.

@ -64,24 +64,24 @@ grpc_error_handle ParseRetryThrottling(const Json& json,
intptr_t* max_milli_tokens, intptr_t* max_milli_tokens,
intptr_t* milli_token_ratio) { intptr_t* milli_token_ratio) {
if (json.type() != Json::Type::OBJECT) { if (json.type() != Json::Type::OBJECT) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"field:retryThrottling error:Type should be object"); "field:retryThrottling error:Type should be object");
} }
std::vector<grpc_error_handle> error_list; std::vector<grpc_error_handle> error_list;
// Parse maxTokens. // Parse maxTokens.
auto it = json.object_value().find("maxTokens"); auto it = json.object_value().find("maxTokens");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryThrottling field:maxTokens error:Not found")); "field:retryThrottling field:maxTokens error:Not found"));
} else if (it->second.type() != Json::Type::NUMBER) { } else if (it->second.type() != Json::Type::NUMBER) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryThrottling field:maxTokens error:Type should be " "field:retryThrottling field:maxTokens error:Type should be "
"number")); "number"));
} else { } else {
*max_milli_tokens = *max_milli_tokens =
gpr_parse_nonnegative_int(it->second.string_value().c_str()) * 1000; gpr_parse_nonnegative_int(it->second.string_value().c_str()) * 1000;
if (*max_milli_tokens <= 0) { if (*max_milli_tokens <= 0) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryThrottling field:maxTokens error:should be " "field:retryThrottling field:maxTokens error:should be "
"greater than zero")); "greater than zero"));
} }
@ -89,10 +89,10 @@ grpc_error_handle ParseRetryThrottling(const Json& json,
// Parse tokenRatio. // Parse tokenRatio.
it = json.object_value().find("tokenRatio"); it = json.object_value().find("tokenRatio");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryThrottling field:tokenRatio error:Not found")); "field:retryThrottling field:tokenRatio error:Not found"));
} else if (it->second.type() != Json::Type::NUMBER) { } else if (it->second.type() != Json::Type::NUMBER) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryThrottling field:tokenRatio error:type should be " "field:retryThrottling field:tokenRatio error:type should be "
"number")); "number"));
} else { } else {
@ -109,7 +109,7 @@ grpc_error_handle ParseRetryThrottling(const Json& json,
if (decimal_len > 3) decimal_len = 3; if (decimal_len > 3) decimal_len = 3;
if (!gpr_parse_bytes_to_uint32(decimal_point + 1, decimal_len, if (!gpr_parse_bytes_to_uint32(decimal_point + 1, decimal_len,
&decimal_value)) { &decimal_value)) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryThrottling field:tokenRatio error:Failed " "field:retryThrottling field:tokenRatio error:Failed "
"parsing")); "parsing"));
return GRPC_ERROR_CREATE_FROM_VECTOR("retryThrottling", &error_list); return GRPC_ERROR_CREATE_FROM_VECTOR("retryThrottling", &error_list);
@ -122,7 +122,7 @@ grpc_error_handle ParseRetryThrottling(const Json& json,
} }
uint32_t whole_value; uint32_t whole_value;
if (!gpr_parse_bytes_to_uint32(value, whole_len, &whole_value)) { if (!gpr_parse_bytes_to_uint32(value, whole_len, &whole_value)) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryThrottling field:tokenRatio error:Failed " "field:retryThrottling field:tokenRatio error:Failed "
"parsing")); "parsing"));
return GRPC_ERROR_CREATE_FROM_VECTOR("retryThrottling", &error_list); return GRPC_ERROR_CREATE_FROM_VECTOR("retryThrottling", &error_list);
@ -130,7 +130,7 @@ grpc_error_handle ParseRetryThrottling(const Json& json,
*milli_token_ratio = *milli_token_ratio =
static_cast<int>((whole_value * multiplier) + decimal_value); static_cast<int>((whole_value * multiplier) + decimal_value);
if (*milli_token_ratio <= 0) { if (*milli_token_ratio <= 0) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryThrottling field:tokenRatio error:value should " "field:retryThrottling field:tokenRatio error:value should "
"be greater than 0")); "be greater than 0"));
} }
@ -167,25 +167,25 @@ grpc_error_handle ParseRetryPolicy(
StatusCodeSet* retryable_status_codes, StatusCodeSet* retryable_status_codes,
absl::optional<Duration>* per_attempt_recv_timeout) { absl::optional<Duration>* per_attempt_recv_timeout) {
if (json.type() != Json::Type::OBJECT) { if (json.type() != Json::Type::OBJECT) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"field:retryPolicy error:should be of type object"); "field:retryPolicy error:should be of type object");
} }
std::vector<grpc_error_handle> error_list; std::vector<grpc_error_handle> error_list;
// Parse maxAttempts. // Parse maxAttempts.
auto it = json.object_value().find("maxAttempts"); auto it = json.object_value().find("maxAttempts");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"field:maxAttempts error:required field missing")); GRPC_ERROR_CREATE("field:maxAttempts error:required field missing"));
} else { } else {
if (it->second.type() != Json::Type::NUMBER) { if (it->second.type() != Json::Type::NUMBER) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:maxAttempts error:should be of type number")); "field:maxAttempts error:should be of type number"));
} else { } else {
*max_attempts = *max_attempts =
gpr_parse_nonnegative_int(it->second.string_value().c_str()); gpr_parse_nonnegative_int(it->second.string_value().c_str());
if (*max_attempts <= 1) { if (*max_attempts <= 1) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"field:maxAttempts error:should be at least 2")); GRPC_ERROR_CREATE("field:maxAttempts error:should be at least 2"));
} else if (*max_attempts > MAX_MAX_RETRY_ATTEMPTS) { } else if (*max_attempts > MAX_MAX_RETRY_ATTEMPTS) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"service config: clamped retryPolicy.maxAttempts at %d", "service config: clamped retryPolicy.maxAttempts at %d",
@ -198,32 +198,32 @@ grpc_error_handle ParseRetryPolicy(
if (ParseJsonObjectFieldAsDuration(json.object_value(), "initialBackoff", if (ParseJsonObjectFieldAsDuration(json.object_value(), "initialBackoff",
initial_backoff, &error_list) && initial_backoff, &error_list) &&
*initial_backoff == Duration::Zero()) { *initial_backoff == Duration::Zero()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"field:initialBackoff error:must be greater than 0")); GRPC_ERROR_CREATE("field:initialBackoff error:must be greater than 0"));
} }
// Parse maxBackoff. // Parse maxBackoff.
if (ParseJsonObjectFieldAsDuration(json.object_value(), "maxBackoff", if (ParseJsonObjectFieldAsDuration(json.object_value(), "maxBackoff",
max_backoff, &error_list) && max_backoff, &error_list) &&
*max_backoff == Duration::Zero()) { *max_backoff == Duration::Zero()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"field:maxBackoff error:must be greater than 0")); GRPC_ERROR_CREATE("field:maxBackoff error:must be greater than 0"));
} }
// Parse backoffMultiplier. // Parse backoffMultiplier.
it = json.object_value().find("backoffMultiplier"); it = json.object_value().find("backoffMultiplier");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:backoffMultiplier error:required field missing")); "field:backoffMultiplier error:required field missing"));
} else { } else {
if (it->second.type() != Json::Type::NUMBER) { if (it->second.type() != Json::Type::NUMBER) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:backoffMultiplier error:should be of type number")); "field:backoffMultiplier error:should be of type number"));
} else { } else {
if (sscanf(it->second.string_value().c_str(), "%f", backoff_multiplier) != if (sscanf(it->second.string_value().c_str(), "%f", backoff_multiplier) !=
1) { 1) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"field:backoffMultiplier error:failed to parse")); GRPC_ERROR_CREATE("field:backoffMultiplier error:failed to parse"));
} else if (*backoff_multiplier <= 0) { } else if (*backoff_multiplier <= 0) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:backoffMultiplier error:must be greater than 0")); "field:backoffMultiplier error:must be greater than 0"));
} }
} }
@ -232,12 +232,12 @@ grpc_error_handle ParseRetryPolicy(
it = json.object_value().find("retryableStatusCodes"); it = json.object_value().find("retryableStatusCodes");
if (it != json.object_value().end()) { if (it != json.object_value().end()) {
if (it->second.type() != Json::Type::ARRAY) { if (it->second.type() != Json::Type::ARRAY) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryableStatusCodes error:must be of type array")); "field:retryableStatusCodes error:must be of type array"));
} else { } else {
for (const Json& element : it->second.array_value()) { for (const Json& element : it->second.array_value()) {
if (element.type() != Json::Type::STRING) { if (element.type() != Json::Type::STRING) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryableStatusCodes error:status codes should be of type " "field:retryableStatusCodes error:status codes should be of type "
"string")); "string"));
continue; continue;
@ -245,7 +245,7 @@ grpc_error_handle ParseRetryPolicy(
grpc_status_code status; grpc_status_code status;
if (!grpc_status_code_from_string(element.string_value().c_str(), if (!grpc_status_code_from_string(element.string_value().c_str(),
&status)) { &status)) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryableStatusCodes error:failed to parse status code")); "field:retryableStatusCodes error:failed to parse status code"));
continue; continue;
} }
@ -259,7 +259,7 @@ grpc_error_handle ParseRetryPolicy(
if (it != json.object_value().end()) { if (it != json.object_value().end()) {
Duration per_attempt_recv_timeout_value; Duration per_attempt_recv_timeout_value;
if (!ParseDurationFromJson(it->second, &per_attempt_recv_timeout_value)) { if (!ParseDurationFromJson(it->second, &per_attempt_recv_timeout_value)) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:perAttemptRecvTimeout error:type must be STRING of the " "field:perAttemptRecvTimeout error:type must be STRING of the "
"form given by google.proto.Duration.")); "form given by google.proto.Duration."));
} else { } else {
@ -267,14 +267,14 @@ grpc_error_handle ParseRetryPolicy(
// TODO(roth): As part of implementing hedging, relax this check such // TODO(roth): As part of implementing hedging, relax this check such
// that we allow a value of 0 if a hedging policy is specified. // that we allow a value of 0 if a hedging policy is specified.
if (per_attempt_recv_timeout_value == Duration::Zero()) { if (per_attempt_recv_timeout_value == Duration::Zero()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:perAttemptRecvTimeout error:must be greater than 0")); "field:perAttemptRecvTimeout error:must be greater than 0"));
} }
} }
} else if (retryable_status_codes->Empty()) { } else if (retryable_status_codes->Empty()) {
// If perAttemptRecvTimeout not present, retryableStatusCodes must be // If perAttemptRecvTimeout not present, retryableStatusCodes must be
// non-empty. // non-empty.
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryableStatusCodes error:must be non-empty if " "field:retryableStatusCodes error:must be non-empty if "
"perAttemptRecvTimeout not present")); "perAttemptRecvTimeout not present"));
} }
@ -282,7 +282,7 @@ grpc_error_handle ParseRetryPolicy(
// Hedging not enabled, so the error message for // Hedging not enabled, so the error message for
// retryableStatusCodes unset should be different. // retryableStatusCodes unset should be different.
if (retryable_status_codes->Empty()) { if (retryable_status_codes->Empty()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:retryableStatusCodes error:must be non-empty")); "field:retryableStatusCodes error:must be non-empty"));
} }
} }

@ -84,9 +84,9 @@ class TimerState {
grpc_deadline_state* deadline_state = grpc_deadline_state* deadline_state =
static_cast<grpc_deadline_state*>(self->elem_->call_data); static_cast<grpc_deadline_state*>(self->elem_->call_data);
if (error != absl::CancelledError()) { if (error != absl::CancelledError()) {
error = grpc_error_set_int( error = grpc_error_set_int(GRPC_ERROR_CREATE("Deadline Exceeded"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Deadline Exceeded"), StatusIntProperty::kRpcStatus,
StatusIntProperty::kRpcStatus, GRPC_STATUS_DEADLINE_EXCEEDED); GRPC_STATUS_DEADLINE_EXCEEDED);
deadline_state->call_combiner->Cancel(error); deadline_state->call_combiner->Cancel(error);
GRPC_CLOSURE_INIT(&self->closure_, SendCancelOpInCallCombiner, self, GRPC_CLOSURE_INIT(&self->closure_, SendCancelOpInCallCombiner, self,
nullptr); nullptr);

@ -44,7 +44,7 @@ ParseFaultInjectionPolicy(const Json::Array& policies_json_array,
fault_injection_policy; fault_injection_policy;
std::vector<grpc_error_handle> sub_error_list; std::vector<grpc_error_handle> sub_error_list;
if (policies_json_array[i].type() != Json::Type::OBJECT) { if (policies_json_array[i].type() != Json::Type::OBJECT) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( error_list->push_back(GRPC_ERROR_CREATE(absl::StrCat(
"faultInjectionPolicy index ", i, " is not a JSON object"))); "faultInjectionPolicy index ", i, " is not a JSON object")));
continue; continue;
} }
@ -55,7 +55,7 @@ ParseFaultInjectionPolicy(const Json::Array& policies_json_array,
&sub_error_list, false)) { &sub_error_list, false)) {
if (!grpc_status_code_from_string(abort_code_string.c_str(), if (!grpc_status_code_from_string(abort_code_string.c_str(),
&(fault_injection_policy.abort_code))) { &(fault_injection_policy.abort_code))) {
sub_error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( sub_error_list.push_back(GRPC_ERROR_CREATE(
"field:abortCode error:failed to parse status code")); "field:abortCode error:failed to parse status code"));
} }
} }
@ -85,7 +85,7 @@ ParseFaultInjectionPolicy(const Json::Array& policies_json_array,
if (fault_injection_policy.abort_percentage_denominator != 100 && if (fault_injection_policy.abort_percentage_denominator != 100 &&
fault_injection_policy.abort_percentage_denominator != 10000 && fault_injection_policy.abort_percentage_denominator != 10000 &&
fault_injection_policy.abort_percentage_denominator != 1000000) { fault_injection_policy.abort_percentage_denominator != 1000000) {
sub_error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( sub_error_list.push_back(GRPC_ERROR_CREATE(
"field:abortPercentageDenominator error:Denominator can only be " "field:abortPercentageDenominator error:Denominator can only be "
"one of " "one of "
"100, 10000, 1000000")); "100, 10000, 1000000"));
@ -115,7 +115,7 @@ ParseFaultInjectionPolicy(const Json::Array& policies_json_array,
if (fault_injection_policy.delay_percentage_denominator != 100 && if (fault_injection_policy.delay_percentage_denominator != 100 &&
fault_injection_policy.delay_percentage_denominator != 10000 && fault_injection_policy.delay_percentage_denominator != 10000 &&
fault_injection_policy.delay_percentage_denominator != 1000000) { fault_injection_policy.delay_percentage_denominator != 1000000) {
sub_error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( sub_error_list.push_back(GRPC_ERROR_CREATE(
"field:delayPercentageDenominator error:Denominator can only be " "field:delayPercentageDenominator error:Denominator can only be "
"one of " "one of "
"100, 10000, 1000000")); "100, 10000, 1000000"));
@ -129,7 +129,7 @@ ParseFaultInjectionPolicy(const Json::Array& policies_json_array,
&fault_injection_policy.max_faults, &sub_error_list, &fault_injection_policy.max_faults, &sub_error_list,
false); false);
if (!sub_error_list.empty()) { if (!sub_error_list.empty()) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR(
absl::StrCat("failed to parse faultInjectionPolicy index ", i), absl::StrCat("failed to parse faultInjectionPolicy index ", i),
&sub_error_list)); &sub_error_list));
} }

@ -176,7 +176,7 @@ void CallData::OnRecvMessageReady(void* arg, grpc_error_handle error) {
static_cast<uint32_t>(calld->max_recv_message_length_)) { static_cast<uint32_t>(calld->max_recv_message_length_)) {
GPR_DEBUG_ASSERT(calld->error_.ok()); GPR_DEBUG_ASSERT(calld->error_.ok());
calld->error_ = grpc_error_set_int( calld->error_ = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_CPP_STRING( GRPC_ERROR_CREATE(
absl::StrFormat("Received message larger than max (%u vs. %d)", absl::StrFormat("Received message larger than max (%u vs. %d)",
(*calld->recv_message_)->Length(), (*calld->recv_message_)->Length(),
calld->max_recv_message_length_)), calld->max_recv_message_length_)),
@ -188,7 +188,7 @@ void CallData::OnRecvMessageReady(void* arg, grpc_error_handle error) {
(*calld->recv_message_)->c_slice_buffer(), (*calld->recv_message_)->c_slice_buffer(),
decompressed_slices.c_slice_buffer()) == 0) { decompressed_slices.c_slice_buffer()) == 0) {
GPR_DEBUG_ASSERT(calld->error_.ok()); GPR_DEBUG_ASSERT(calld->error_.ok());
calld->error_ = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( calld->error_ = GRPC_ERROR_CREATE(absl::StrCat(
"Unexpected error decompressing data for algorithm with " "Unexpected error decompressing data for algorithm with "
"enum value ", "enum value ",
calld->algorithm_)); calld->algorithm_));

@ -85,13 +85,13 @@ MessageSizeParser::ParsePerMethodParams(const ChannelArgs& /*args*/,
if (it != json.object_value().end()) { if (it != json.object_value().end()) {
if (it->second.type() != Json::Type::STRING && if (it->second.type() != Json::Type::STRING &&
it->second.type() != Json::Type::NUMBER) { it->second.type() != Json::Type::NUMBER) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:maxRequestMessageBytes error:should be of type number")); "field:maxRequestMessageBytes error:should be of type number"));
} else { } else {
max_request_message_bytes = max_request_message_bytes =
gpr_parse_nonnegative_int(it->second.string_value().c_str()); gpr_parse_nonnegative_int(it->second.string_value().c_str());
if (max_request_message_bytes == -1) { if (max_request_message_bytes == -1) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:maxRequestMessageBytes error:should be non-negative")); "field:maxRequestMessageBytes error:should be non-negative"));
} }
} }
@ -102,13 +102,13 @@ MessageSizeParser::ParsePerMethodParams(const ChannelArgs& /*args*/,
if (it != json.object_value().end()) { if (it != json.object_value().end()) {
if (it->second.type() != Json::Type::STRING && if (it->second.type() != Json::Type::STRING &&
it->second.type() != Json::Type::NUMBER) { it->second.type() != Json::Type::NUMBER) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:maxResponseMessageBytes error:should be of type number")); "field:maxResponseMessageBytes error:should be of type number"));
} else { } else {
max_response_message_bytes = max_response_message_bytes =
gpr_parse_nonnegative_int(it->second.string_value().c_str()); gpr_parse_nonnegative_int(it->second.string_value().c_str());
if (max_response_message_bytes == -1) { if (max_response_message_bytes == -1) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"field:maxResponseMessageBytes error:should be non-negative")); "field:maxResponseMessageBytes error:should be non-negative"));
} }
} }
@ -218,7 +218,7 @@ static void recv_message_ready(void* user_data, grpc_error_handle error) {
(*calld->recv_message)->Length() > (*calld->recv_message)->Length() >
static_cast<size_t>(calld->limits.max_recv_size)) { static_cast<size_t>(calld->limits.max_recv_size)) {
grpc_error_handle new_error = grpc_error_set_int( grpc_error_handle new_error = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( GRPC_ERROR_CREATE(absl::StrFormat(
"Received message larger than max (%u vs. %d)", "Received message larger than max (%u vs. %d)",
(*calld->recv_message)->Length(), calld->limits.max_recv_size)), (*calld->recv_message)->Length(), calld->limits.max_recv_size)),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,
@ -274,7 +274,7 @@ static void message_size_start_transport_stream_op_batch(
static_cast<size_t>(calld->limits.max_send_size)) { static_cast<size_t>(calld->limits.max_send_size)) {
grpc_transport_stream_op_batch_finish_with_failure( grpc_transport_stream_op_batch_finish_with_failure(
op, op,
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( grpc_error_set_int(GRPC_ERROR_CREATE(absl::StrFormat(
"Sent message larger than max (%u vs. %d)", "Sent message larger than max (%u vs. %d)",
op->payload->send_message.send_message->Length(), op->payload->send_message.send_message->Length(),
calld->limits.max_send_size)), calld->limits.max_send_size)),

@ -93,7 +93,7 @@ void RbacFilter::CallData::RecvInitialMetadataReady(void* user_data,
service_config_call_data->GetMethodParsedConfig( service_config_call_data->GetMethodParsedConfig(
filter->service_config_parser_index_)); filter->service_config_parser_index_));
if (method_params == nullptr) { if (method_params == nullptr) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("No RBAC policy found."); error = GRPC_ERROR_CREATE("No RBAC policy found.");
} else { } else {
RbacFilter* chand = static_cast<RbacFilter*>(elem->channel_data); RbacFilter* chand = static_cast<RbacFilter*>(elem->channel_data);
auto* authorization_engine = auto* authorization_engine =
@ -102,8 +102,7 @@ void RbacFilter::CallData::RecvInitialMetadataReady(void* user_data,
->Evaluate(EvaluateArgs(calld->recv_initial_metadata_, ->Evaluate(EvaluateArgs(calld->recv_initial_metadata_,
&chand->per_channel_evaluate_args_)) &chand->per_channel_evaluate_args_))
.type == AuthorizationEngine::Decision::Type::kDeny) { .type == AuthorizationEngine::Decision::Type::kDeny) {
error = error = GRPC_ERROR_CREATE("Unauthorized RPC rejected");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unauthorized RPC rejected");
} }
} }
if (!error.ok()) { if (!error.ok()) {
@ -147,14 +146,14 @@ grpc_error_handle RbacFilter::Init(grpc_channel_element* elem,
GPR_ASSERT(elem->filter == &kFilterVtable); GPR_ASSERT(elem->filter == &kFilterVtable);
auto* auth_context = grpc_find_auth_context_in_args(args->channel_args); auto* auth_context = grpc_find_auth_context_in_args(args->channel_args);
if (auth_context == nullptr) { if (auth_context == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No auth context found"); return GRPC_ERROR_CREATE("No auth context found");
} }
auto* transport = grpc_channel_args_find_pointer<grpc_transport>( auto* transport = grpc_channel_args_find_pointer<grpc_transport>(
args->channel_args, GRPC_ARG_TRANSPORT); args->channel_args, GRPC_ARG_TRANSPORT);
if (transport == nullptr) { if (transport == nullptr) {
// This should never happen since the transport is always set on the server // This should never happen since the transport is always set on the server
// side. // side.
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No transport configured"); return GRPC_ERROR_CREATE("No transport configured");
} }
new (elem->channel_data) RbacFilter( new (elem->channel_data) RbacFilter(
grpc_channel_stack_filter_instance_number(args->channel_stack, elem), grpc_channel_stack_filter_instance_number(args->channel_stack, elem),

@ -195,7 +195,7 @@ Rbac::Permission ParsePermission(const Json::Object& permission_json,
permissions.emplace_back(std::make_unique<Rbac::Permission>( permissions.emplace_back(std::make_unique<Rbac::Permission>(
ParsePermission(*permission_json, &permission_error_list))); ParsePermission(*permission_json, &permission_error_list)));
if (!permission_error_list.empty()) { if (!permission_error_list.empty()) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR(
absl::StrFormat("rules[%d]", i), &permission_error_list)); absl::StrFormat("rules[%d]", i), &permission_error_list));
} }
} }
@ -306,8 +306,7 @@ Rbac::Permission ParsePermission(const Json::Object& permission_json,
"requestedServerName", &req_server_name_error_list)); "requestedServerName", &req_server_name_error_list));
} }
} else { } else {
error_list->push_back( error_list->push_back(GRPC_ERROR_CREATE("No valid rule found"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("No valid rule found"));
} }
return permission; return permission;
} }
@ -331,7 +330,7 @@ Rbac::Principal ParsePrincipal(const Json::Object& principal_json,
principals.emplace_back(std::make_unique<Rbac::Principal>( principals.emplace_back(std::make_unique<Rbac::Principal>(
ParsePrincipal(*principal_json, &principal_error_list))); ParsePrincipal(*principal_json, &principal_error_list)));
if (!principal_error_list.empty()) { if (!principal_error_list.empty()) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR(
absl::StrFormat("ids[%d]", i), &principal_error_list)); absl::StrFormat("ids[%d]", i), &principal_error_list));
} }
} }
@ -467,8 +466,7 @@ Rbac::Principal ParsePrincipal(const Json::Object& principal_json,
GRPC_ERROR_CREATE_FROM_VECTOR("notId", &not_rule_error_list)); GRPC_ERROR_CREATE_FROM_VECTOR("notId", &not_rule_error_list));
} }
} else { } else {
error_list->push_back( error_list->push_back(GRPC_ERROR_CREATE("No valid id found"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("No valid id found"));
} }
return principal; return principal;
} }
@ -491,7 +489,7 @@ Rbac::Policy ParsePolicy(const Json::Object& policy_json,
permissions.emplace_back(std::make_unique<Rbac::Permission>( permissions.emplace_back(std::make_unique<Rbac::Permission>(
ParsePermission(*permission_json, &permission_error_list))); ParsePermission(*permission_json, &permission_error_list)));
if (!permission_error_list.empty()) { if (!permission_error_list.empty()) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR(
absl::StrFormat("permissions[%d]", i), &permission_error_list)); absl::StrFormat("permissions[%d]", i), &permission_error_list));
} }
} }
@ -511,7 +509,7 @@ Rbac::Policy ParsePolicy(const Json::Object& policy_json,
principals.emplace_back(std::make_unique<Rbac::Principal>( principals.emplace_back(std::make_unique<Rbac::Principal>(
ParsePrincipal(*principal_json, &principal_error_list))); ParsePrincipal(*principal_json, &principal_error_list)));
if (!principal_error_list.empty()) { if (!principal_error_list.empty()) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR(
absl::StrFormat("principals[%d]", i), &principal_error_list)); absl::StrFormat("principals[%d]", i), &principal_error_list));
} }
} }
@ -535,8 +533,7 @@ Rbac ParseRbac(const Json::Object& rbac_json,
int action; int action;
if (ParseJsonObjectField(*rules_json, "action", &action, error_list)) { if (ParseJsonObjectField(*rules_json, "action", &action, error_list)) {
if (action > 1) { if (action > 1) {
error_list->push_back( error_list->push_back(GRPC_ERROR_CREATE("Unknown action"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unknown action"));
} }
} }
rbac.action = static_cast<Rbac::Action>(action); rbac.action = static_cast<Rbac::Action>(action);
@ -549,7 +546,7 @@ Rbac ParseRbac(const Json::Object& rbac_json,
entry.first, entry.first,
ParsePolicy(entry.second.object_value(), &policy_error_list)); ParsePolicy(entry.second.object_value(), &policy_error_list));
if (!policy_error_list.empty()) { if (!policy_error_list.empty()) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR(
absl::StrFormat("policies key:'%s'", entry.first.c_str()), absl::StrFormat("policies key:'%s'", entry.first.c_str()),
&policy_error_list)); &policy_error_list));
} }
@ -571,7 +568,7 @@ std::vector<Rbac> ParseRbacArray(const Json::Array& policies_json_array,
std::vector<grpc_error_handle> rbac_policy_error_list; std::vector<grpc_error_handle> rbac_policy_error_list;
policies.emplace_back(ParseRbac(*rbac_json, &rbac_policy_error_list)); policies.emplace_back(ParseRbac(*rbac_json, &rbac_policy_error_list));
if (!rbac_policy_error_list.empty()) { if (!rbac_policy_error_list.empty()) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE_FROM_VECTOR(
absl::StrFormat("rbacPolicy[%d]", i), &rbac_policy_error_list)); absl::StrFormat("rbacPolicy[%d]", i), &rbac_policy_error_list));
} }
} }

@ -212,7 +212,7 @@ static void recv_initial_metadata_locked(void* arg,
if (!gbs->is_client) { if (!gbs->is_client) {
// For server, we expect :authority and :path in initial metadata. // For server, we expect :authority and :path in initial metadata.
if (!ContainsAuthorityAndPath(*args->initial_metadata)) { if (!ContainsAuthorityAndPath(*args->initial_metadata)) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
"Missing :authority or :path in initial metadata"); "Missing :authority or :path in initial metadata");
} }
} }
@ -575,9 +575,9 @@ static void close_transport_locked(grpc_binder_transport* gbt) {
while (!gbt->registered_stream.empty()) { while (!gbt->registered_stream.empty()) {
cancel_stream_locked( cancel_stream_locked(
gbt, gbt->registered_stream.begin()->second, gbt, gbt->registered_stream.begin()->second,
grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("transport closed"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("transport closed"), grpc_core::StatusIntProperty::kRpcStatus,
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE)); GRPC_STATUS_UNAVAILABLE));
} }
} }
@ -630,7 +630,7 @@ static void destroy_stream_locked(void* sp, grpc_error_handle /*error*/) {
grpc_binder_transport* gbt = gbs->t; grpc_binder_transport* gbt = gbs->t;
cancel_stream_locked( cancel_stream_locked(
gbt, gbs, gbt, gbs,
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("destroy stream"), grpc_error_set_int(GRPC_ERROR_CREATE("destroy stream"),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,
GRPC_STATUS_UNAVAILABLE)); GRPC_STATUS_UNAVAILABLE));
gbs->~grpc_binder_stream(); gbs->~grpc_binder_stream();

@ -110,8 +110,7 @@ void Chttp2Connector::Connect(const Args& args, Result* result,
} }
absl::StatusOr<std::string> address = grpc_sockaddr_to_uri(args.address); absl::StatusOr<std::string> address = grpc_sockaddr_to_uri(args.address);
if (!address.ok()) { if (!address.ok()) {
grpc_error_handle error = grpc_error_handle error = GRPC_ERROR_CREATE(address.status().ToString());
GRPC_ERROR_CREATE_FROM_CPP_STRING(address.status().ToString());
NullThenSchedClosure(DEBUG_LOCATION, &notify_, error); NullThenSchedClosure(DEBUG_LOCATION, &notify_, error);
return; return;
} }
@ -145,7 +144,7 @@ void Chttp2Connector::OnHandshakeDone(void* arg, grpc_error_handle error) {
MutexLock lock(&self->mu_); MutexLock lock(&self->mu_);
if (!error.ok() || self->shutdown_) { if (!error.ok() || self->shutdown_) {
if (error.ok()) { if (error.ok()) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("connector shutdown"); error = GRPC_ERROR_CREATE("connector shutdown");
// We were shut down after handshaking completed successfully, so // We were shut down after handshaking completed successfully, so
// destroy the endpoint here. // destroy the endpoint here.
if (args->endpoint != nullptr) { if (args->endpoint != nullptr) {
@ -229,7 +228,7 @@ void Chttp2Connector::OnTimeout(void* arg, grpc_error_handle /*error*/) {
// SubchannelConnector::Result::Reset() // SubchannelConnector::Result::Reset()
grpc_transport_destroy(self->result_->transport); grpc_transport_destroy(self->result_->transport);
self->result_->Reset(); self->result_->Reset();
self->MaybeNotify(GRPC_ERROR_CREATE_FROM_STATIC_STRING( self->MaybeNotify(GRPC_ERROR_CREATE(
"connection attempt timed out before receiving SETTINGS frame")); "connection attempt timed out before receiving SETTINGS frame"));
} else { } else {
// OnReceiveSettings() was already invoked. Call Notify() again so that // OnReceiveSettings() was already invoked. Call Notify() again so that

@ -388,8 +388,7 @@ void Chttp2ServerListener::ActiveConnection::HandshakingState::Orphan() {
{ {
MutexLock lock(&connection_->mu_); MutexLock lock(&connection_->mu_);
if (handshake_mgr_ != nullptr) { if (handshake_mgr_ != nullptr) {
handshake_mgr_->Shutdown( handshake_mgr_->Shutdown(GRPC_ERROR_CREATE("Listener stopped serving."));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Listener stopped serving."));
} }
} }
Unref(); Unref();
@ -415,7 +414,7 @@ void Chttp2ServerListener::ActiveConnection::HandshakingState::OnTimeout(
// or with an error indicating that the timer system is being shut down. // or with an error indicating that the timer system is being shut down.
if (error != absl::CancelledError()) { if (error != absl::CancelledError()) {
grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_transport_op* op = grpc_make_transport_op(nullptr);
op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( op->disconnect_with_error = GRPC_ERROR_CREATE(
"Did not receive HTTP/2 settings before handshake timeout"); "Did not receive HTTP/2 settings before handshake timeout");
grpc_chttp2_transport* transport = nullptr; grpc_chttp2_transport* transport = nullptr;
{ {
@ -598,8 +597,8 @@ void Chttp2ServerListener::ActiveConnection::SendGoAway() {
} }
if (transport != nullptr) { if (transport != nullptr) {
grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_transport_op* op = grpc_make_transport_op(nullptr);
op->goaway_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( op->goaway_error =
"Server is stopping to serve requests."); GRPC_ERROR_CREATE("Server is stopping to serve requests.");
grpc_transport_perform_op(&transport->base, op); grpc_transport_perform_op(&transport->base, op);
} }
} }
@ -656,7 +655,7 @@ void Chttp2ServerListener::ActiveConnection::OnDrainGraceTimeExpiry(
transport = self->transport_; transport = self->transport_;
} }
grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_transport_op* op = grpc_make_transport_op(nullptr);
op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( op->disconnect_with_error = GRPC_ERROR_CREATE(
"Drain grace time expired. Closing connection immediately."); "Drain grace time expired. Closing connection immediately.");
grpc_transport_perform_op(&transport->base, op); grpc_transport_perform_op(&transport->base, op);
} }
@ -695,8 +694,7 @@ grpc_error_handle Chttp2ServerListener::Create(
.value_or(GRPC_ENABLE_CHANNELZ_DEFAULT)) { .value_or(GRPC_ENABLE_CHANNELZ_DEFAULT)) {
auto string_address = grpc_sockaddr_to_uri(addr); auto string_address = grpc_sockaddr_to_uri(addr);
if (!string_address.ok()) { if (!string_address.ok()) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(string_address.status().ToString());
string_address.status().ToString());
} }
listener->channelz_listen_socket_ = listener->channelz_listen_socket_ =
MakeRefCounted<channelz::ListenSocketNode>( MakeRefCounted<channelz::ListenSocketNode>(
@ -807,7 +805,7 @@ void Chttp2ServerListener::OnAccept(void* arg, grpc_endpoint* tcp,
}; };
if (self->server_->config_fetcher() != nullptr) { if (self->server_->config_fetcher() != nullptr) {
if (connection_manager == nullptr) { if (connection_manager == nullptr) {
grpc_error_handle error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( grpc_error_handle error = GRPC_ERROR_CREATE(
"No ConnectionManager configured. Closing connection."); "No ConnectionManager configured. Closing connection.");
endpoint_cleanup(error); endpoint_cleanup(error);
return; return;
@ -817,8 +815,7 @@ void Chttp2ServerListener::OnAccept(void* arg, grpc_endpoint* tcp,
if (!args_result.ok()) { if (!args_result.ok()) {
gpr_log(GPR_DEBUG, "Closing connection: %s", gpr_log(GPR_DEBUG, "Closing connection: %s",
args_result.status().ToString().c_str()); args_result.status().ToString().c_str());
endpoint_cleanup( endpoint_cleanup(GRPC_ERROR_CREATE(args_result.status().ToString()));
GRPC_ERROR_CREATE_FROM_CPP_STRING(args_result.status().ToString()));
return; return;
} }
grpc_error_handle error; grpc_error_handle error;
@ -908,8 +905,7 @@ grpc_error_handle Chttp2ServerAddPort(Server* server, const char* addr,
Chttp2ServerArgsModifier args_modifier, Chttp2ServerArgsModifier args_modifier,
int* port_num) { int* port_num) {
if (addr == nullptr) { if (addr == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Invalid address: addr cannot be a nullptr.");
"Invalid address: addr cannot be a nullptr.");
} }
if (strncmp(addr, "external:", 9) == 0) { if (strncmp(addr, "external:", 9) == 0) {
return Chttp2ServerListener::CreateWithAcceptor(server, addr, args, return Chttp2ServerListener::CreateWithAcceptor(server, addr, args,
@ -960,15 +956,15 @@ grpc_error_handle Chttp2ServerAddPort(Server* server, const char* addr,
std::string msg = absl::StrFormat( std::string msg = absl::StrFormat(
"No address added out of total %" PRIuPTR " resolved for '%s'", "No address added out of total %" PRIuPTR " resolved for '%s'",
resolved_or->size(), addr); resolved_or->size(), addr);
return GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING( return GRPC_ERROR_CREATE_REFERENCING(msg.c_str(), error_list.data(),
msg.c_str(), error_list.data(), error_list.size()); error_list.size());
} else if (!error_list.empty()) { } else if (!error_list.empty()) {
std::string msg = absl::StrFormat( std::string msg = absl::StrFormat(
"Only %" PRIuPTR " addresses added out of total %" PRIuPTR "Only %" PRIuPTR " addresses added out of total %" PRIuPTR
" resolved", " resolved",
resolved_or->size() - error_list.size(), resolved_or->size()); resolved_or->size() - error_list.size(), resolved_or->size());
error = GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING( error = GRPC_ERROR_CREATE_REFERENCING(msg.c_str(), error_list.data(),
msg.c_str(), error_list.data(), error_list.size()); error_list.size());
gpr_log(GPR_INFO, "WARNING: %s", grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "WARNING: %s", grpc_error_std_string(error).c_str());
// we managed to bind some addresses: continue without error // we managed to bind some addresses: continue without error
} }
@ -984,13 +980,12 @@ ChannelArgs ModifyArgsForConnection(const ChannelArgs& args,
grpc_error_handle* error) { grpc_error_handle* error) {
auto* server_credentials = args.GetObject<grpc_server_credentials>(); auto* server_credentials = args.GetObject<grpc_server_credentials>();
if (server_credentials == nullptr) { if (server_credentials == nullptr) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("Could not find server credentials");
"Could not find server credentials");
return args; return args;
} }
auto security_connector = server_credentials->create_security_connector(args); auto security_connector = server_credentials->create_security_connector(args);
if (security_connector == nullptr) { if (security_connector == nullptr) {
*error = GRPC_ERROR_CREATE_FROM_CPP_STRING( *error = GRPC_ERROR_CREATE(
absl::StrCat("Unable to create secure server with credentials of type ", absl::StrCat("Unable to create secure server with credentials of type ",
server_credentials->type().name())); server_credentials->type().name()));
return args; return args;
@ -1013,7 +1008,7 @@ int grpc_server_add_http2_port(grpc_server* server, const char* addr,
(server, addr, creds)); (server, addr, creds));
// Create security context. // Create security context.
if (creds == nullptr) { if (creds == nullptr) {
err = GRPC_ERROR_CREATE_FROM_STATIC_STRING( err = GRPC_ERROR_CREATE(
"No credentials specified for secure server port (creds==NULL)"); "No credentials specified for secure server port (creds==NULL)");
goto done; goto done;
} }
@ -1033,7 +1028,7 @@ int grpc_server_add_http2_port(grpc_server* server, const char* addr,
} else { } else {
sc = creds->create_security_connector(grpc_core::ChannelArgs()); sc = creds->create_security_connector(grpc_core::ChannelArgs());
if (sc == nullptr) { if (sc == nullptr) {
err = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( err = GRPC_ERROR_CREATE(absl::StrCat(
"Unable to create secure server with credentials of type ", "Unable to create secure server with credentials of type ",
creds->type().name())); creds->type().name()));
goto done; goto done;

@ -234,8 +234,7 @@ grpc_chttp2_transport::~grpc_chttp2_transport() {
grpc_slice_buffer_destroy(&outbuf); grpc_slice_buffer_destroy(&outbuf);
grpc_error_handle error = grpc_error_handle error = GRPC_ERROR_CREATE("Transport destroyed");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed");
// ContextList::Execute follows semantics of a callback function and does not // ContextList::Execute follows semantics of a callback function and does not
// take a ref on error // take a ref on error
grpc_core::ContextList::Execute(cl, nullptr, error); grpc_core::ContextList::Execute(cl, nullptr, error);
@ -255,8 +254,7 @@ grpc_chttp2_transport::~grpc_chttp2_transport() {
GRPC_COMBINER_UNREF(combiner, "chttp2_transport"); GRPC_COMBINER_UNREF(combiner, "chttp2_transport");
cancel_pings(this, cancel_pings(this, GRPC_ERROR_CREATE("Transport destroyed"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"));
while (write_cb_pool) { while (write_cb_pool) {
grpc_chttp2_write_cb* next = write_cb_pool->next; grpc_chttp2_write_cb* next = write_cb_pool->next;
@ -539,10 +537,9 @@ static void destroy_transport_locked(void* tp, grpc_error_handle /*error*/) {
grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
t->destroying = 1; t->destroying = 1;
close_transport_locked( close_transport_locked(
t, t, grpc_error_set_int(GRPC_ERROR_CREATE("Transport destroyed"),
grpc_error_set_int( grpc_core::StatusIntProperty::kOccurredDuringWrite,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"), t->write_state));
grpc_core::StatusIntProperty::kOccurredDuringWrite, t->write_state));
t->memory_owner.Reset(); t->memory_owner.Reset();
// Must be the last line. // Must be the last line.
GRPC_CHTTP2_UNREF_TRANSPORT(t, "destroy"); GRPC_CHTTP2_UNREF_TRANSPORT(t, "destroy");
@ -567,8 +564,7 @@ static void close_transport_locked(grpc_chttp2_transport* t,
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.ok()) { if (t->close_transport_on_writes_finished.ok()) {
t->close_transport_on_writes_finished = t->close_transport_on_writes_finished =
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("Delayed close due to in-progress write");
"Delayed close due to in-progress write");
} }
t->close_transport_on_writes_finished = t->close_transport_on_writes_finished =
grpc_error_add_child(t->close_transport_on_writes_finished, error); grpc_error_add_child(t->close_transport_on_writes_finished, error);
@ -906,8 +902,7 @@ static void write_action_end_locked(void* tp, grpc_error_handle error) {
t->sent_goaway_state = GRPC_CHTTP2_FINAL_GOAWAY_SENT; t->sent_goaway_state = GRPC_CHTTP2_FINAL_GOAWAY_SENT;
closed = true; closed = true;
if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) { if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
close_transport_locked( close_transport_locked(t, GRPC_ERROR_CREATE("goaway sent"));
t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent"));
} }
} }
@ -977,10 +972,9 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t,
} }
t->goaway_error = grpc_error_set_str( t->goaway_error = grpc_error_set_str(
grpc_error_set_int( grpc_error_set_int(
grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("GOAWAY received"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("GOAWAY received"), grpc_core::StatusIntProperty::kHttp2Error,
grpc_core::StatusIntProperty::kHttp2Error, static_cast<intptr_t>(goaway_error)),
static_cast<intptr_t>(goaway_error)),
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE), grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE),
grpc_core::StatusStrProperty::kRawBytes, goaway_text); grpc_core::StatusStrProperty::kRawBytes, goaway_text);
@ -1085,10 +1079,9 @@ static void maybe_start_some_streams(grpc_chttp2_transport* t) {
grpc_core::GrpcStreamNetworkState::kNotSentOnWire); grpc_core::GrpcStreamNetworkState::kNotSentOnWire);
grpc_chttp2_cancel_stream( grpc_chttp2_cancel_stream(
t, s, t, s,
grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("Stream IDs exhausted"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"), grpc_core::StatusIntProperty::kRpcStatus,
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE));
GRPC_STATUS_UNAVAILABLE));
} }
} }
} }
@ -1146,7 +1139,7 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t,
grpc_error_handle cl_err = grpc_error_handle cl_err =
grpc_core::internal::StatusMoveFromHeapPtr(closure->error_data.error); grpc_core::internal::StatusMoveFromHeapPtr(closure->error_data.error);
if (cl_err.ok()) { if (cl_err.ok()) {
cl_err = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( cl_err = GRPC_ERROR_CREATE(absl::StrCat(
"Error in HTTP transport completing operation: ", desc, "Error in HTTP transport completing operation: ", desc,
" write_state=", write_state_name(t->write_state), " refs=", " write_state=", write_state_name(t->write_state), " refs=",
closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT, " flags=", closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT, " flags=",
@ -1258,8 +1251,8 @@ static void perform_stream_op_locked(void* stream_op,
grpc_chttp2_cancel_stream( grpc_chttp2_cancel_stream(
t, s, t, s,
grpc_error_set_int( grpc_error_set_int(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( GRPC_ERROR_CREATE_REFERENCING("Transport closed",
"Transport closed", &t->closed_with_error, 1), &t->closed_with_error, 1),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,
GRPC_STATUS_UNAVAILABLE)); GRPC_STATUS_UNAVAILABLE));
} }
@ -1276,7 +1269,7 @@ static void perform_stream_op_locked(void* stream_op,
s->send_initial_metadata = nullptr; s->send_initial_metadata = nullptr;
grpc_chttp2_complete_closure_step( grpc_chttp2_complete_closure_step(
t, s, &s->send_initial_metadata_finished, t, s, &s->send_initial_metadata_finished,
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( GRPC_ERROR_CREATE_REFERENCING(
"Attempt to send initial metadata after stream was closed", "Attempt to send initial metadata after stream was closed",
&s->write_closed_error, 1), &s->write_closed_error, 1),
"send_initial_metadata_finished"); "send_initial_metadata_finished");
@ -1381,9 +1374,8 @@ static void perform_stream_op_locked(void* stream_op,
t, s, &s->send_trailing_metadata_finished, t, s, &s->send_trailing_metadata_finished,
op->payload->send_trailing_metadata.send_trailing_metadata->empty() op->payload->send_trailing_metadata.send_trailing_metadata->empty()
? absl::OkStatus() ? absl::OkStatus()
: GRPC_ERROR_CREATE_FROM_STATIC_STRING( : GRPC_ERROR_CREATE("Attempt to send trailing metadata after "
"Attempt to send trailing metadata after " "stream was closed"),
"stream was closed"),
"send_trailing_metadata_finished"); "send_trailing_metadata_finished");
} else if (s->id != 0) { } else if (s->id != 0) {
// TODO(ctiller): check if there's flow control for any outstanding // TODO(ctiller): check if there's flow control for any outstanding
@ -1693,17 +1685,15 @@ void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t) {
if (++t->ping_recv_state.ping_strikes > t->ping_policy.max_ping_strikes && if (++t->ping_recv_state.ping_strikes > t->ping_policy.max_ping_strikes &&
t->ping_policy.max_ping_strikes != 0) { t->ping_policy.max_ping_strikes != 0) {
send_goaway(t, send_goaway(t,
grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("too_many_pings"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("too_many_pings"), grpc_core::StatusIntProperty::kHttp2Error,
grpc_core::StatusIntProperty::kHttp2Error, GRPC_HTTP2_ENHANCE_YOUR_CALM),
GRPC_HTTP2_ENHANCE_YOUR_CALM),
/*immediate_disconnect_hint=*/true); /*immediate_disconnect_hint=*/true);
// The transport will be closed after the write is done // The transport will be closed after the write is done
close_transport_locked( close_transport_locked(
t, t, grpc_error_set_int(GRPC_ERROR_CREATE("Too many pings"),
grpc_error_set_int( grpc_core::StatusIntProperty::kRpcStatus,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"), GRPC_STATUS_UNAVAILABLE));
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE));
} }
} }
@ -1903,7 +1893,7 @@ static void remove_stream(grpc_chttp2_transport* t, uint32_t id,
post_benign_reclaimer(t); post_benign_reclaimer(t);
if (t->sent_goaway_state == GRPC_CHTTP2_FINAL_GOAWAY_SENT) { if (t->sent_goaway_state == GRPC_CHTTP2_FINAL_GOAWAY_SENT) {
close_transport_locked( close_transport_locked(
t, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( t, GRPC_ERROR_CREATE_REFERENCING(
"Last stream closed after sending GOAWAY", &error, 1)); "Last stream closed after sending GOAWAY", &error, 1));
} }
} }
@ -1990,8 +1980,7 @@ static grpc_error_handle removal_error(grpc_error_handle extra_error,
add_error(extra_error, refs, &nrefs); add_error(extra_error, refs, &nrefs);
grpc_error_handle error; grpc_error_handle error;
if (nrefs > 0) { if (nrefs > 0) {
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(main_error_msg, error = GRPC_ERROR_CREATE_REFERENCING(main_error_msg, refs, nrefs);
refs, nrefs);
} }
return error; return error;
} }
@ -2326,10 +2315,9 @@ static grpc_error_handle try_http_parsing(grpc_chttp2_transport* t) {
if (parse_error.ok() && if (parse_error.ok() &&
(parse_error = grpc_http_parser_eof(&parser)) == absl::OkStatus()) { (parse_error = grpc_http_parser_eof(&parser)) == absl::OkStatus()) {
error = grpc_error_set_int( error = grpc_error_set_int(
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( grpc_error_set_int(
"Trying to connect an http1.x server"), GRPC_ERROR_CREATE("Trying to connect an http1.x server"),
grpc_core::StatusIntProperty::kHttpStatus, grpc_core::StatusIntProperty::kHttpStatus, response.status),
response.status),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,
grpc_http2_status_to_grpc_status(response.status)); grpc_http2_status_to_grpc_status(response.status));
} }
@ -2351,10 +2339,9 @@ static void read_action_locked(void* tp, grpc_error_handle error) {
grpc_error_handle err = error; grpc_error_handle err = error;
if (!err.ok()) { if (!err.ok()) {
err = grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( err = grpc_error_set_int(
"Endpoint read failed", &err, 1), GRPC_ERROR_CREATE_REFERENCING("Endpoint read failed", &err, 1),
grpc_core::StatusIntProperty::kOccurredDuringWrite, grpc_core::StatusIntProperty::kOccurredDuringWrite, t->write_state);
t->write_state);
} }
std::swap(err, error); std::swap(err, error);
if (t->closed_with_error.ok()) { if (t->closed_with_error.ok()) {
@ -2365,8 +2352,8 @@ static void read_action_locked(void* tp, grpc_error_handle error) {
} }
if (errors[1] != absl::OkStatus()) { if (errors[1] != absl::OkStatus()) {
errors[2] = try_http_parsing(t); errors[2] = try_http_parsing(t);
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE_REFERENCING("Failed parsing HTTP/2", errors,
"Failed parsing HTTP/2", errors, GPR_ARRAY_SIZE(errors)); GPR_ARRAY_SIZE(errors));
} }
for (i = 0; i < GPR_ARRAY_SIZE(errors); i++) { for (i = 0; i < GPR_ARRAY_SIZE(errors); i++) {
} }
@ -2386,8 +2373,8 @@ static void read_action_locked(void* tp, grpc_error_handle error) {
bool keep_reading = false; bool keep_reading = false;
if (error.ok() && !t->closed_with_error.ok()) { if (error.ok() && !t->closed_with_error.ok()) {
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE_REFERENCING("Transport closed",
"Transport closed", &t->closed_with_error, 1); &t->closed_with_error, 1);
} }
if (!error.ok()) { if (!error.ok()) {
// If a goaway frame was received, this might be the reason why the read // If a goaway frame was received, this might be the reason why the read
@ -2719,8 +2706,7 @@ static void keepalive_watchdog_fired_locked(void* arg,
t->peer_string.c_str()); t->peer_string.c_str());
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING;
close_transport_locked( close_transport_locked(
t, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( t, grpc_error_set_int(GRPC_ERROR_CREATE("keepalive watchdog timeout"),
"keepalive watchdog timeout"),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,
GRPC_STATUS_UNAVAILABLE)); GRPC_STATUS_UNAVAILABLE));
} }
@ -2818,12 +2804,11 @@ static void benign_reclaimer_locked(void* arg, grpc_error_handle error) {
gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory", gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory",
t->peer_string.c_str()); t->peer_string.c_str());
} }
send_goaway( send_goaway(t,
t, grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"),
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), grpc_core::StatusIntProperty::kHttp2Error,
grpc_core::StatusIntProperty::kHttp2Error, GRPC_HTTP2_ENHANCE_YOUR_CALM),
GRPC_HTTP2_ENHANCE_YOUR_CALM), /*immediate_disconnect_hint=*/true);
/*immediate_disconnect_hint=*/true);
} else if (error.ok() && GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { } else if (error.ok() && GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR
@ -2851,7 +2836,7 @@ static void destructive_reclaimer_locked(void* arg, grpc_error_handle error) {
} }
grpc_chttp2_cancel_stream( grpc_chttp2_cancel_stream(
t, s, t, s,
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"),
grpc_core::StatusIntProperty::kHttp2Error, grpc_core::StatusIntProperty::kHttp2Error,
GRPC_HTTP2_ENHANCE_YOUR_CALM)); GRPC_HTTP2_ENHANCE_YOUR_CALM));
if (n > 1) { if (n > 1) {

@ -104,7 +104,7 @@ grpc_core::Poll<grpc_error_handle> grpc_deframe_unprocessed_incoming_frames(
} }
break; break;
default: default:
error = GRPC_ERROR_CREATE_FROM_CPP_STRING( error = GRPC_ERROR_CREATE(
absl::StrFormat("Bad GRPC frame type 0x%02x", header[0])); absl::StrFormat("Bad GRPC frame type 0x%02x", header[0]));
error = grpc_error_set_int(error, grpc_core::StatusIntProperty::kStreamId, error = grpc_error_set_int(error, grpc_core::StatusIntProperty::kStreamId,
static_cast<intptr_t>(s->id)); static_cast<intptr_t>(s->id));
@ -147,9 +147,9 @@ grpc_error_handle grpc_chttp2_data_parser_parse(void* /*parser*/,
if (is_last && s->received_last_frame) { if (is_last && s->received_last_frame) {
grpc_chttp2_mark_stream_closed( grpc_chttp2_mark_stream_closed(
t, s, true, false, t, s, true, false,
t->is_client ? GRPC_ERROR_CREATE_FROM_STATIC_STRING( t->is_client
"Data frame with END_STREAM flag received") ? GRPC_ERROR_CREATE("Data frame with END_STREAM flag received")
: absl::OkStatus()); : absl::OkStatus());
} }
return absl::OkStatus(); return absl::OkStatus();

@ -44,7 +44,7 @@ void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser* p) {
grpc_error_handle grpc_chttp2_goaway_parser_begin_frame( grpc_error_handle grpc_chttp2_goaway_parser_begin_frame(
grpc_chttp2_goaway_parser* p, uint32_t length, uint8_t /*flags*/) { grpc_chttp2_goaway_parser* p, uint32_t length, uint8_t /*flags*/) {
if (length < 8) { if (length < 8) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrFormat("goaway frame too short (%d bytes)", length)); absl::StrFormat("goaway frame too short (%d bytes)", length));
} }
@ -149,8 +149,7 @@ grpc_error_handle grpc_chttp2_goaway_parser_parse(void* parser,
} }
return absl::OkStatus(); return absl::OkStatus();
} }
GPR_UNREACHABLE_CODE( GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"));
} }
void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code,

@ -64,7 +64,7 @@ grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes) {
grpc_error_handle grpc_chttp2_ping_parser_begin_frame( grpc_error_handle grpc_chttp2_ping_parser_begin_frame(
grpc_chttp2_ping_parser* parser, uint32_t length, uint8_t flags) { grpc_chttp2_ping_parser* parser, uint32_t length, uint8_t flags) {
if (flags & 0xfe || length != 8) { if (flags & 0xfe || length != 8) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrFormat("invalid ping: length=%d, flags=%02x", length, flags)); absl::StrFormat("invalid ping: length=%d, flags=%02x", length, flags));
} }
parser->byte = 0; parser->byte = 0;

@ -77,7 +77,7 @@ void grpc_chttp2_add_rst_stream_to_next_write(
grpc_error_handle grpc_chttp2_rst_stream_parser_begin_frame( grpc_error_handle grpc_chttp2_rst_stream_parser_begin_frame(
grpc_chttp2_rst_stream_parser* parser, uint32_t length, uint8_t flags) { grpc_chttp2_rst_stream_parser* parser, uint32_t length, uint8_t flags) {
if (length != 4) { if (length != 4) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return GRPC_ERROR_CREATE(absl::StrFormat(
"invalid rst_stream: length=%d, flags=%02x", length, flags)); "invalid rst_stream: length=%d, flags=%02x", length, flags));
} }
parser->byte = 0; parser->byte = 0;
@ -117,7 +117,7 @@ grpc_error_handle grpc_chttp2_rst_stream_parser_parse(void* parser,
if (reason != GRPC_HTTP2_NO_ERROR || s->trailing_metadata_buffer.empty()) { if (reason != GRPC_HTTP2_NO_ERROR || s->trailing_metadata_buffer.empty()) {
error = grpc_error_set_int( error = grpc_error_set_int(
grpc_error_set_str( grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("RST_STREAM"), GRPC_ERROR_CREATE("RST_STREAM"),
grpc_core::StatusStrProperty::kGrpcMessage, grpc_core::StatusStrProperty::kGrpcMessage,
absl::StrCat("Received RST_STREAM with error code ", reason)), absl::StrCat("Received RST_STREAM with error code ", reason)),
grpc_core::StatusIntProperty::kHttp2Error, grpc_core::StatusIntProperty::kHttp2Error,

@ -103,16 +103,13 @@ grpc_error_handle grpc_chttp2_settings_parser_begin_frame(
if (flags == GRPC_CHTTP2_FLAG_ACK) { if (flags == GRPC_CHTTP2_FLAG_ACK) {
parser->is_ack = 1; parser->is_ack = 1;
if (length != 0) { if (length != 0) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("non-empty settings ack frame received");
"non-empty settings ack frame received");
} }
return absl::OkStatus(); return absl::OkStatus();
} else if (flags != 0) { } else if (flags != 0) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("invalid flags on settings frame");
"invalid flags on settings frame");
} else if (length % 6 != 0) { } else if (length % 6 != 0) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("settings frames must be a multiple of six bytes");
"settings frames must be a multiple of six bytes");
} else { } else {
return absl::OkStatus(); return absl::OkStatus();
} }
@ -213,7 +210,7 @@ grpc_error_handle grpc_chttp2_settings_parser_parse(void* p,
t->last_new_stream_id, sp->error_value, t->last_new_stream_id, sp->error_value,
grpc_slice_from_static_string("HTTP2 settings error"), grpc_slice_from_static_string("HTTP2 settings error"),
&t->qbuf); &t->qbuf);
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return GRPC_ERROR_CREATE(absl::StrFormat(
"invalid value %u passed for %s", parser->value, sp->name)); "invalid value %u passed for %s", parser->value, sp->name));
} }
} }

@ -60,7 +60,7 @@ grpc_slice grpc_chttp2_window_update_create(
grpc_error_handle grpc_chttp2_window_update_parser_begin_frame( grpc_error_handle grpc_chttp2_window_update_parser_begin_frame(
grpc_chttp2_window_update_parser* parser, uint32_t length, uint8_t flags) { grpc_chttp2_window_update_parser* parser, uint32_t length, uint8_t flags) {
if (flags || length != 4) { if (flags || length != 4) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return GRPC_ERROR_CREATE(absl::StrFormat(
"invalid window update: length=%d, flags=%02x", length, flags)); "invalid window update: length=%d, flags=%02x", length, flags));
} }
parser->byte = 0; parser->byte = 0;
@ -91,7 +91,7 @@ grpc_error_handle grpc_chttp2_window_update_parser_parse(
// top bit is reserved and must be ignored. // top bit is reserved and must be ignored.
uint32_t received_update = p->amount & 0x7fffffffu; uint32_t received_update = p->amount & 0x7fffffffu;
if (received_update == 0) { if (received_update == 0) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrCat("invalid window update bytes: ", p->amount)); absl::StrCat("invalid window update bytes: ", p->amount));
} }
GPR_ASSERT(is_last); GPR_ASSERT(is_last);

@ -633,7 +633,7 @@ class HPackParser::Input {
uint8_t last_byte) { uint8_t last_byte) {
return MaybeSetErrorAndReturn( return MaybeSetErrorAndReturn(
[value, last_byte] { [value, last_byte] {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return GRPC_ERROR_CREATE(absl::StrFormat(
"integer overflow in hpack integer decoding: have 0x%08x, " "integer overflow in hpack integer decoding: have 0x%08x, "
"got byte 0x%02x on byte 5", "got byte 0x%02x on byte 5",
value, last_byte)); value, last_byte));
@ -831,10 +831,7 @@ class HPackParser::String {
} }
if (!result.has_value()) { if (!result.has_value()) {
return input->MaybeSetErrorAndReturn( return input->MaybeSetErrorAndReturn(
[] { [] { return GRPC_ERROR_CREATE("illegal base64 encoding"); },
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"illegal base64 encoding");
},
absl::optional<String>()); absl::optional<String>());
} }
return String(std::move(*result)); return String(std::move(*result));
@ -1016,11 +1013,7 @@ class HPackParser::Parser {
if (cur == 0x80) { if (cur == 0x80) {
// illegal value. // illegal value.
return input_->MaybeSetErrorAndReturn( return input_->MaybeSetErrorAndReturn(
[] { [] { return GRPC_ERROR_CREATE("Illegal hpack op code"); }, false);
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Illegal hpack op code");
},
false);
} }
ABSL_FALLTHROUGH_INTENDED; ABSL_FALLTHROUGH_INTENDED;
case 9: case 9:
@ -1172,7 +1165,7 @@ class HPackParser::Parser {
if (*dynamic_table_updates_allowed_ == 0) { if (*dynamic_table_updates_allowed_ == 0) {
return input_->MaybeSetErrorAndReturn( return input_->MaybeSetErrorAndReturn(
[] { [] {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"More than two max table size changes in a single frame"); "More than two max table size changes in a single frame");
}, },
false); false);
@ -1193,10 +1186,9 @@ class HPackParser::Parser {
return input_->MaybeSetErrorAndReturn( return input_->MaybeSetErrorAndReturn(
[this, index] { [this, index] {
return grpc_error_set_int( return grpc_error_set_int(
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( grpc_error_set_int(
"Invalid HPACK index received"), GRPC_ERROR_CREATE("Invalid HPACK index received"),
StatusIntProperty::kIndex, StatusIntProperty::kIndex, static_cast<intptr_t>(index)),
static_cast<intptr_t>(index)),
StatusIntProperty::kSize, StatusIntProperty::kSize,
static_cast<intptr_t>(this->table_->num_entries())); static_cast<intptr_t>(this->table_->num_entries()));
}, },
@ -1214,8 +1206,7 @@ class HPackParser::Parser {
return input_->MaybeSetErrorAndReturn( return input_->MaybeSetErrorAndReturn(
[] { [] {
return grpc_error_set_int( return grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("received initial metadata size exceeds limit"),
"received initial metadata size exceeds limit"),
StatusIntProperty::kRpcStatus, GRPC_STATUS_RESOURCE_EXHAUSTED); StatusIntProperty::kRpcStatus, GRPC_STATUS_RESOURCE_EXHAUSTED);
}, },
false); false);
@ -1289,7 +1280,7 @@ grpc_error_handle HPackParser::ParseInput(Input input, bool is_last) {
} }
if (input.eof_error()) { if (input.eof_error()) {
if (GPR_UNLIKELY(is_last && is_boundary())) { if (GPR_UNLIKELY(is_last && is_boundary())) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"Incomplete header at the end of a header/continuation sequence"); "Incomplete header at the end of a header/continuation sequence");
} }
unparsed_bytes_ = std::vector<uint8_t>(input.frontier(), input.end_ptr()); unparsed_bytes_ = std::vector<uint8_t>(input.frontier(), input.end_ptr());
@ -1365,8 +1356,7 @@ grpc_error_handle grpc_chttp2_header_parser_parse(void* hpack_parser,
if (s != nullptr) { if (s != nullptr) {
if (parser->is_boundary()) { if (parser->is_boundary()) {
if (s->header_frames_received == 2) { if (s->header_frames_received == 2) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Too many trailer frames");
"Too many trailer frames");
} }
s->published_metadata[s->header_frames_received] = s->published_metadata[s->header_frames_received] =
GRPC_METADATA_PUBLISHED_FROM_WIRE; GRPC_METADATA_PUBLISHED_FROM_WIRE;

@ -104,7 +104,7 @@ grpc_error_handle HPackTable::SetCurrentTableSize(uint32_t bytes) {
return absl::OkStatus(); return absl::OkStatus();
} }
if (bytes > max_bytes_) { if (bytes > max_bytes_) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return GRPC_ERROR_CREATE(absl::StrFormat(
"Attempt to make hpack table %d bytes when max is %d bytes", bytes, "Attempt to make hpack table %d bytes when max is %d bytes", bytes,
max_bytes_)); max_bytes_));
} }
@ -123,7 +123,7 @@ grpc_error_handle HPackTable::SetCurrentTableSize(uint32_t bytes) {
grpc_error_handle HPackTable::Add(Memento md) { grpc_error_handle HPackTable::Add(Memento md) {
if (current_table_bytes_ > max_bytes_) { if (current_table_bytes_ > max_bytes_) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return GRPC_ERROR_CREATE(absl::StrFormat(
"HPACK max table size reduced to %d but not reflected by hpack " "HPACK max table size reduced to %d but not reflected by hpack "
"stream (still at %d)", "stream (still at %d)",
max_bytes_, current_table_bytes_)); max_bytes_, current_table_bytes_));

@ -160,7 +160,7 @@ grpc_error_handle grpc_chttp2_perform_read(grpc_chttp2_transport* t,
case GRPC_DTS_CLIENT_PREFIX_23: case GRPC_DTS_CLIENT_PREFIX_23:
while (cur != end && t->deframe_state != GRPC_DTS_FH_0) { while (cur != end && t->deframe_state != GRPC_DTS_FH_0) {
if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state]) { if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state]) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return GRPC_ERROR_CREATE(absl::StrFormat(
"Connect string mismatch: expected '%c' (%d) got '%c' (%d) " "Connect string mismatch: expected '%c' (%d) got '%c' (%d) "
"at byte %d", "at byte %d",
get_utf8_safe_char( get_utf8_safe_char(
@ -266,7 +266,7 @@ grpc_error_handle grpc_chttp2_perform_read(grpc_chttp2_transport* t,
} else if (t->incoming_frame_size > } else if (t->incoming_frame_size >
t->settings[GRPC_ACKED_SETTINGS] t->settings[GRPC_ACKED_SETTINGS]
[GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE]) { [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE]) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrFormat("Frame size %d is larger than max frame size %d", absl::StrFormat("Frame size %d is larger than max frame size %d",
t->incoming_frame_size, t->incoming_frame_size,
t->settings[GRPC_ACKED_SETTINGS] t->settings[GRPC_ACKED_SETTINGS]
@ -324,19 +324,19 @@ grpc_error_handle grpc_chttp2_perform_read(grpc_chttp2_transport* t,
static grpc_error_handle init_frame_parser(grpc_chttp2_transport* t) { static grpc_error_handle init_frame_parser(grpc_chttp2_transport* t) {
if (t->is_first_frame && if (t->is_first_frame &&
t->incoming_frame_type != GRPC_CHTTP2_FRAME_SETTINGS) { t->incoming_frame_type != GRPC_CHTTP2_FRAME_SETTINGS) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( return GRPC_ERROR_CREATE(absl::StrCat(
"Expected SETTINGS frame as the first frame, got frame type ", "Expected SETTINGS frame as the first frame, got frame type ",
t->incoming_frame_type)); t->incoming_frame_type));
} }
t->is_first_frame = false; t->is_first_frame = false;
if (t->expect_continuation_stream_id != 0) { if (t->expect_continuation_stream_id != 0) {
if (t->incoming_frame_type != GRPC_CHTTP2_FRAME_CONTINUATION) { if (t->incoming_frame_type != GRPC_CHTTP2_FRAME_CONTINUATION) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrFormat("Expected CONTINUATION frame, got frame type %02x", absl::StrFormat("Expected CONTINUATION frame, got frame type %02x",
t->incoming_frame_type)); t->incoming_frame_type));
} }
if (t->expect_continuation_stream_id != t->incoming_stream_id) { if (t->expect_continuation_stream_id != t->incoming_stream_id) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return GRPC_ERROR_CREATE(absl::StrFormat(
"Expected CONTINUATION frame for grpc_chttp2_stream %08x, got " "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got "
"grpc_chttp2_stream %08x", "grpc_chttp2_stream %08x",
t->expect_continuation_stream_id, t->incoming_stream_id)); t->expect_continuation_stream_id, t->incoming_stream_id));
@ -349,8 +349,7 @@ static grpc_error_handle init_frame_parser(grpc_chttp2_transport* t) {
case GRPC_CHTTP2_FRAME_HEADER: case GRPC_CHTTP2_FRAME_HEADER:
return init_header_frame_parser(t, 0); return init_header_frame_parser(t, 0);
case GRPC_CHTTP2_FRAME_CONTINUATION: case GRPC_CHTTP2_FRAME_CONTINUATION:
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Unexpected CONTINUATION frame");
"Unexpected CONTINUATION frame");
case GRPC_CHTTP2_FRAME_RST_STREAM: case GRPC_CHTTP2_FRAME_RST_STREAM:
return init_rst_stream_parser(t); return init_rst_stream_parser(t);
case GRPC_CHTTP2_FRAME_SETTINGS: case GRPC_CHTTP2_FRAME_SETTINGS:
@ -550,7 +549,7 @@ static grpc_error_handle init_header_frame_parser(grpc_chttp2_transport* t,
grpc_chttp2_stream_map_size(&t->stream_map) >= grpc_chttp2_stream_map_size(&t->stream_map) >=
t->settings[GRPC_ACKED_SETTINGS] t->settings[GRPC_ACKED_SETTINGS]
[GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS])) { [GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS])) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Max stream count exceeded"); return GRPC_ERROR_CREATE("Max stream count exceeded");
} else if (t->sent_goaway_state == GRPC_CHTTP2_FINAL_GOAWAY_SENT) { } else if (t->sent_goaway_state == GRPC_CHTTP2_FINAL_GOAWAY_SENT) {
GRPC_CHTTP2_IF_TRACING(gpr_log( GRPC_CHTTP2_IF_TRACING(gpr_log(
GPR_INFO, GPR_INFO,
@ -614,7 +613,7 @@ static grpc_error_handle init_header_frame_parser(grpc_chttp2_transport* t,
return init_header_skip_frame_parser(t, priority_type); return init_header_skip_frame_parser(t, priority_type);
} }
if (frame_type == HPackParser::LogInfo::kTrailers && !t->header_eof) { if (frame_type == HPackParser::LogInfo::kTrailers && !t->header_eof) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"Trailing metadata frame received without an end-o-stream"); "Trailing metadata frame received without an end-o-stream");
} }
t->hpack_parser.BeginFrame( t->hpack_parser.BeginFrame(
@ -680,8 +679,7 @@ static grpc_error_handle init_goaway_parser(grpc_chttp2_transport* t) {
static grpc_error_handle init_settings_frame_parser(grpc_chttp2_transport* t) { static grpc_error_handle init_settings_frame_parser(grpc_chttp2_transport* t) {
if (t->incoming_stream_id != 0) { if (t->incoming_stream_id != 0) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Settings frame received for grpc_chttp2_stream");
"Settings frame received for grpc_chttp2_stream");
} }
grpc_error_handle err = grpc_chttp2_settings_parser_begin_frame( grpc_error_handle err = grpc_chttp2_settings_parser_begin_frame(

@ -319,7 +319,7 @@ static void read_grpc_header(stream_obj* s) {
static grpc_error_handle make_error_with_desc(int error_code, static grpc_error_handle make_error_with_desc(int error_code,
int cronet_internal_error_code, int cronet_internal_error_code,
const char* desc) { const char* desc) {
return grpc_error_set_int(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( return grpc_error_set_int(GRPC_ERROR_CREATE(absl::StrFormat(
"Cronet error code:%d, Cronet error detail:%s", "Cronet error code:%d, Cronet error detail:%s",
cronet_internal_error_code, desc)), cronet_internal_error_code, desc)),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,

@ -627,7 +627,7 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
if (*destfilled || s->trailing_md_sent) { if (*destfilled || s->trailing_md_sent) {
// The buffer is already in use; that's an error! // The buffer is already in use; that's an error!
INPROC_LOG(GPR_INFO, "Extra trailing metadata %p", s); INPROC_LOG(GPR_INFO, "Extra trailing metadata %p", s);
new_err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Extra trailing metadata"); new_err = GRPC_ERROR_CREATE("Extra trailing metadata");
fail_helper_locked(s, new_err); fail_helper_locked(s, new_err);
goto done; goto done;
} else { } else {
@ -666,8 +666,7 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
} }
if (s->recv_initial_md_op) { if (s->recv_initial_md_op) {
if (s->initial_md_recvd) { if (s->initial_md_recvd) {
new_err = new_err = GRPC_ERROR_CREATE("Already recvd initial md");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already recvd initial md");
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 "
@ -724,8 +723,7 @@ void op_state_machine_locked(inproc_stream* s, grpc_error_handle error) {
s->to_read_trailing_md_filled = false; s->to_read_trailing_md_filled = false;
s->trailing_md_recvd_implicit_only = false; s->trailing_md_recvd_implicit_only = false;
} else { } else {
new_err = new_err = GRPC_ERROR_CREATE("Already recvd trailing md");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already recvd trailing md");
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 "
@ -961,7 +959,7 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
inproc_stream* other = s->other_side; inproc_stream* other = s->other_side;
if (error.ok() && (op->send_initial_metadata || op->send_trailing_metadata)) { if (error.ok() && (op->send_initial_metadata || op->send_trailing_metadata)) {
if (s->t->is_closed) { if (s->t->is_closed) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Endpoint already shutdown"); error = GRPC_ERROR_CREATE("Endpoint already shutdown");
} }
if (error.ok() && op->send_initial_metadata) { if (error.ok() && op->send_initial_metadata) {
grpc_metadata_batch* dest = (other == nullptr) grpc_metadata_batch* dest = (other == nullptr)
@ -972,7 +970,7 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
if (*destfilled || s->initial_md_sent) { if (*destfilled || s->initial_md_sent) {
// The buffer is already in use; that's an error! // The buffer is already in use; that's an error!
INPROC_LOG(GPR_INFO, "Extra initial metadata %p", s); INPROC_LOG(GPR_INFO, "Extra initial metadata %p", s);
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Extra initial metadata"); error = GRPC_ERROR_CREATE("Extra initial metadata");
} else { } else {
if (!s->other_side_closed) { if (!s->other_side_closed) {
fill_in_metadata( fill_in_metadata(
@ -1100,10 +1098,9 @@ void close_transport_locked(inproc_transport* t) {
// cancel_stream_locked also adjusts stream list // cancel_stream_locked also adjusts stream list
cancel_stream_locked( cancel_stream_locked(
t->stream_list, t->stream_list,
grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("Transport closed"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport closed"), grpc_core::StatusIntProperty::kRpcStatus,
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE));
GRPC_STATUS_UNAVAILABLE));
} }
} }
} }

@ -76,8 +76,7 @@ FileWatcherCertificateProviderFactory::Config::Parse(const Json& config_json,
grpc_error_handle* error) { grpc_error_handle* error) {
auto config = MakeRefCounted<FileWatcherCertificateProviderFactory::Config>(); auto config = MakeRefCounted<FileWatcherCertificateProviderFactory::Config>();
if (config_json.type() != Json::Type::OBJECT) { if (config_json.type() != Json::Type::OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("error:config type should be OBJECT.");
"error:config type should be OBJECT.");
return nullptr; return nullptr;
} }
std::vector<grpc_error_handle> error_list; std::vector<grpc_error_handle> error_list;
@ -87,14 +86,14 @@ FileWatcherCertificateProviderFactory::Config::Parse(const Json& config_json,
&config->private_key_file_, &error_list, false); &config->private_key_file_, &error_list, false);
if (config->identity_cert_file_.empty() != if (config->identity_cert_file_.empty() !=
config->private_key_file_.empty()) { config->private_key_file_.empty()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"fields \"certificate_file\" and \"private_key_file\" must be both set " "fields \"certificate_file\" and \"private_key_file\" must be both set "
"or both unset.")); "or both unset."));
} }
ParseJsonObjectField(config_json.object_value(), "ca_certificate_file", ParseJsonObjectField(config_json.object_value(), "ca_certificate_file",
&config->root_cert_file_, &error_list, false); &config->root_cert_file_, &error_list, false);
if (config->identity_cert_file_.empty() && config->root_cert_file_.empty()) { if (config->identity_cert_file_.empty() && config->root_cert_file_.empty()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(GRPC_ERROR_CREATE(
"At least one of \"certificate_file\" and \"ca_certificate_file\" must " "At least one of \"certificate_file\" and \"ca_certificate_file\" must "
"be specified.")); "be specified."));
} }

@ -112,7 +112,7 @@ GoogleMeshCaCertificateProviderFactory::Config::ParseJsonObjectGoogleGrpc(
if (ParseJsonObjectField(google_grpc, "call_credentials", if (ParseJsonObjectField(google_grpc, "call_credentials",
&call_credentials_array, &error_list_google_grpc)) { &call_credentials_array, &error_list_google_grpc)) {
if (call_credentials_array->size() != 1) { if (call_credentials_array->size() != 1) {
error_list_google_grpc.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list_google_grpc.push_back(GRPC_ERROR_CREATE(
"field:call_credentials error:Need exactly one entry.")); "field:call_credentials error:Need exactly one entry."));
} else { } else {
const Json::Object* call_credentials = nullptr; const Json::Object* call_credentials = nullptr;
@ -160,15 +160,15 @@ GoogleMeshCaCertificateProviderFactory::Config::ParseJsonObjectServer(
if (ParseJsonObjectField(server, "api_type", &api_type, &error_list_server, if (ParseJsonObjectField(server, "api_type", &api_type, &error_list_server,
false)) { false)) {
if (api_type != "GRPC") { if (api_type != "GRPC") {
error_list_server.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list_server.push_back(
"field:api_type error:Only GRPC is supported")); GRPC_ERROR_CREATE("field:api_type error:Only GRPC is supported"));
} }
} }
const Json::Array* grpc_services = nullptr; const Json::Array* grpc_services = nullptr;
if (ParseJsonObjectField(server, "grpc_services", &grpc_services, if (ParseJsonObjectField(server, "grpc_services", &grpc_services,
&error_list_server)) { &error_list_server)) {
if (grpc_services->size() != 1) { if (grpc_services->size() != 1) {
error_list_server.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list_server.push_back(GRPC_ERROR_CREATE(
"field:grpc_services error:Need exactly one entry")); "field:grpc_services error:Need exactly one entry"));
} else { } else {
const Json::Object* grpc_service = nullptr; const Json::Object* grpc_service = nullptr;
@ -192,8 +192,7 @@ GoogleMeshCaCertificateProviderFactory::Config::Parse(
auto config = auto config =
MakeRefCounted<GoogleMeshCaCertificateProviderFactory::Config>(); MakeRefCounted<GoogleMeshCaCertificateProviderFactory::Config>();
if (config_json.type() != Json::Type::OBJECT) { if (config_json.type() != Json::Type::OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("error:config type should be OBJECT.");
"error:config type should be OBJECT.");
return nullptr; return nullptr;
} }
std::vector<grpc_error_handle> error_list; std::vector<grpc_error_handle> error_list;
@ -221,8 +220,8 @@ GoogleMeshCaCertificateProviderFactory::Config::Parse(
if (ParseJsonObjectField(config_json.object_value(), "key_type", &key_type, if (ParseJsonObjectField(config_json.object_value(), "key_type", &key_type,
&error_list, false)) { &error_list, false)) {
if (key_type != "RSA") { if (key_type != "RSA") {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"field:key_type error:Only RSA is supported.")); GRPC_ERROR_CREATE("field:key_type error:Only RSA is supported."));
} }
} }
if (!ParseJsonObjectField(config_json.object_value(), "key_size", if (!ParseJsonObjectField(config_json.object_value(), "key_size",

@ -146,7 +146,7 @@ void XdsCertificateProvider::ClusterCertificateState::
root_cert_watcher_ = nullptr; root_cert_watcher_ = nullptr;
xds_certificate_provider_->distributor_->SetErrorForCert( xds_certificate_provider_->distributor_->SetErrorForCert(
"", "",
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE(
"No certificate provider available for root certificates"), "No certificate provider available for root certificates"),
absl::nullopt); absl::nullopt);
} }
@ -177,7 +177,7 @@ void XdsCertificateProvider::ClusterCertificateState::
identity_cert_watcher_ = nullptr; identity_cert_watcher_ = nullptr;
xds_certificate_provider_->distributor_->SetErrorForCert( xds_certificate_provider_->distributor_->SetErrorForCert(
"", absl::nullopt, "", absl::nullopt,
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE(
"No certificate provider available for identity certificates")); "No certificate provider available for identity certificates"));
} }
} }
@ -219,7 +219,7 @@ void XdsCertificateProvider::ClusterCertificateState::WatchStatusCallback(
if (root_cert_distributor_ == nullptr) { if (root_cert_distributor_ == nullptr) {
xds_certificate_provider_->distributor_->SetErrorForCert( xds_certificate_provider_->distributor_->SetErrorForCert(
cert_name, cert_name,
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE(
"No certificate provider available for root certificates"), "No certificate provider available for root certificates"),
absl::nullopt); absl::nullopt);
} else { } else {
@ -239,7 +239,7 @@ void XdsCertificateProvider::ClusterCertificateState::WatchStatusCallback(
if (identity_cert_distributor_ == nullptr) { if (identity_cert_distributor_ == nullptr) {
xds_certificate_provider_->distributor_->SetErrorForCert( xds_certificate_provider_->distributor_->SetErrorForCert(
cert_name, absl::nullopt, cert_name, absl::nullopt,
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE(
"No certificate provider available for identity certificates")); "No certificate provider available for identity certificates"));
} else { } else {
UpdateIdentityCertWatcher(cert_name, identity_cert_distributor_.get()); UpdateIdentityCertWatcher(cert_name, identity_cert_distributor_.get());

@ -449,7 +449,7 @@ HttpConnectionManagerParse(
envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_rds( envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_rds(
http_connection_manager_proto); http_connection_manager_proto);
if (rds == nullptr) { if (rds == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"HttpConnectionManager neither has inlined route_config nor RDS."); "HttpConnectionManager neither has inlined route_config nor RDS.");
} }
// Check that the ConfigSource specifies ADS. // Check that the ConfigSource specifies ADS.

@ -1181,14 +1181,13 @@ ServerConfigSelector::CallConfig XdsServerConfigFetcher::ListenerWatcher::
grpc_metadata_batch* metadata) { grpc_metadata_batch* metadata) {
CallConfig call_config; CallConfig call_config;
if (metadata->get_pointer(HttpPathMetadata()) == nullptr) { if (metadata->get_pointer(HttpPathMetadata()) == nullptr) {
call_config.error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("No path found"); call_config.error = GRPC_ERROR_CREATE("No path found");
return call_config; return call_config;
} }
absl::string_view path = absl::string_view path =
metadata->get_pointer(HttpPathMetadata())->as_string_view(); metadata->get_pointer(HttpPathMetadata())->as_string_view();
if (metadata->get_pointer(HttpAuthorityMetadata()) == nullptr) { if (metadata->get_pointer(HttpAuthorityMetadata()) == nullptr) {
call_config.error = call_config.error = GRPC_ERROR_CREATE("No authority found");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("No authority found");
return call_config; return call_config;
} }
absl::string_view authority = absl::string_view authority =
@ -1197,9 +1196,8 @@ ServerConfigSelector::CallConfig XdsServerConfigFetcher::ListenerWatcher::
VirtualHostListIterator(&virtual_hosts_), authority); VirtualHostListIterator(&virtual_hosts_), authority);
if (!vhost_index.has_value()) { if (!vhost_index.has_value()) {
call_config.error = grpc_error_set_int( call_config.error = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_CPP_STRING( GRPC_ERROR_CREATE(absl::StrCat("could not find VirtualHost for ",
absl::StrCat("could not find VirtualHost for ", authority, authority, " in RouteConfiguration")),
" in RouteConfiguration")),
StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE); StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE);
return call_config; return call_config;
} }
@ -1211,8 +1209,7 @@ ServerConfigSelector::CallConfig XdsServerConfigFetcher::ListenerWatcher::
// Found the matching route // Found the matching route
if (route.unsupported_action) { if (route.unsupported_action) {
call_config.error = grpc_error_set_int( call_config.error = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("Matching route has unsupported action"),
"Matching route has unsupported action"),
StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE); StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE);
return call_config; return call_config;
} }
@ -1223,9 +1220,9 @@ ServerConfigSelector::CallConfig XdsServerConfigFetcher::ListenerWatcher::
} }
return call_config; return call_config;
} }
call_config.error = grpc_error_set_int( call_config.error = grpc_error_set_int(GRPC_ERROR_CREATE("No route matched"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("No route matched"), StatusIntProperty::kRpcStatus,
StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE); GRPC_STATUS_UNAVAILABLE);
return call_config; return call_config;
} }

@ -84,7 +84,7 @@ grpc_error_handle UnixSockaddrPopulate(absl::string_view path,
reinterpret_cast<struct sockaddr_un*>(resolved_addr->addr); reinterpret_cast<struct sockaddr_un*>(resolved_addr->addr);
const size_t maxlen = sizeof(un->sun_path) - 1; const size_t maxlen = sizeof(un->sun_path) - 1;
if (path.size() > maxlen) { if (path.size() > maxlen) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( return GRPC_ERROR_CREATE(absl::StrCat(
"Path name should not have more than ", maxlen, " characters")); "Path name should not have more than ", maxlen, " characters"));
} }
un->sun_family = AF_UNIX; un->sun_family = AF_UNIX;
@ -101,7 +101,7 @@ grpc_error_handle UnixAbstractSockaddrPopulate(
reinterpret_cast<struct sockaddr_un*>(resolved_addr->addr); reinterpret_cast<struct sockaddr_un*>(resolved_addr->addr);
const size_t maxlen = sizeof(un->sun_path) - 1; const size_t maxlen = sizeof(un->sun_path) - 1;
if (path.size() > maxlen) { if (path.size() > maxlen) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( return GRPC_ERROR_CREATE(absl::StrCat(
"Path name should not have more than ", maxlen, " characters")); "Path name should not have more than ", maxlen, " characters"));
} }
un->sun_family = AF_UNIX; un->sun_family = AF_UNIX;

@ -195,8 +195,7 @@ static grpc_error_handle connected_channel_init_call_elem(
chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld),
&args->call_stack->refcount, args->server_transport_data, args->arena); &args->call_stack->refcount, args->server_transport_data, args->arena);
return r == 0 ? absl::OkStatus() return r == 0 ? absl::OkStatus()
: GRPC_ERROR_CREATE_FROM_STATIC_STRING( : GRPC_ERROR_CREATE("transport stream initialization failed");
"transport stream initialization failed");
} }
static void set_pollset_or_pollset_set(grpc_call_element* elem, static void set_pollset_or_pollset_set(grpc_call_element* elem,

@ -354,8 +354,7 @@ class ClientCallData::PollContext {
GPR_ASSERT(*md->get_pointer(GrpcStatusMetadata()) != GPR_ASSERT(*md->get_pointer(GrpcStatusMetadata()) !=
GRPC_STATUS_OK); GRPC_STATUS_OK);
grpc_error_handle error = grpc_error_set_int( grpc_error_handle error = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("early return from promise based filter"),
"early return from promise based filter"),
StatusIntProperty::kRpcStatus, StatusIntProperty::kRpcStatus,
*md->get_pointer(GrpcStatusMetadata())); *md->get_pointer(GrpcStatusMetadata()));
if (auto* message = md->get_pointer(GrpcMessageMetadata())) { if (auto* message = md->get_pointer(GrpcMessageMetadata())) {
@ -1256,11 +1255,10 @@ void ServerCallData::WakeInsideCombiner(Flusher* flusher) {
break; break;
case SendTrailingState::kInitial: { case SendTrailingState::kInitial: {
GPR_ASSERT(*md->get_pointer(GrpcStatusMetadata()) != GRPC_STATUS_OK); GPR_ASSERT(*md->get_pointer(GrpcStatusMetadata()) != GRPC_STATUS_OK);
grpc_error_handle error = grpc_error_handle error = grpc_error_set_int(
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("early return from promise based filter"),
"early return from promise based filter"), StatusIntProperty::kRpcStatus,
StatusIntProperty::kRpcStatus, *md->get_pointer(GrpcStatusMetadata()));
*md->get_pointer(GrpcStatusMetadata()));
if (auto* message = md->get_pointer(GrpcMessageMetadata())) { if (auto* message = md->get_pointer(GrpcMessageMetadata())) {
error = grpc_error_set_str(error, StatusStrProperty::kGrpcMessage, error = grpc_error_set_str(error, StatusStrProperty::kGrpcMessage,
message->as_string_view()); message->as_string_view());

@ -223,18 +223,16 @@ void HttpRequest::Orphan() {
// cancel potentially pending DNS resolution. // cancel potentially pending DNS resolution.
if (dns_request_handle_.has_value() && if (dns_request_handle_.has_value() &&
resolver_->Cancel(dns_request_handle_.value())) { resolver_->Cancel(dns_request_handle_.value())) {
Finish(GRPC_ERROR_CREATE_FROM_STATIC_STRING( Finish(GRPC_ERROR_CREATE("cancelled during DNS resolution"));
"cancelled during DNS resolution"));
Unref(); Unref();
} }
if (handshake_mgr_ != nullptr) { if (handshake_mgr_ != nullptr) {
// Shutdown will cancel any ongoing tcp connect. // Shutdown will cancel any ongoing tcp connect.
handshake_mgr_->Shutdown(GRPC_ERROR_CREATE_FROM_STATIC_STRING( handshake_mgr_->Shutdown(
"HTTP request cancelled during handshake")); GRPC_ERROR_CREATE("HTTP request cancelled during handshake"));
} }
if (own_endpoint_ && ep_ != nullptr) { if (own_endpoint_ && ep_ != nullptr) {
grpc_endpoint_shutdown( grpc_endpoint_shutdown(ep_, GRPC_ERROR_CREATE("HTTP request cancelled"));
ep_, GRPC_ERROR_CREATE_FROM_STATIC_STRING("HTTP request cancelled"));
} }
} }
Unref(); Unref();
@ -242,8 +240,7 @@ void HttpRequest::Orphan() {
void HttpRequest::AppendError(grpc_error_handle error) { void HttpRequest::AppendError(grpc_error_handle error) {
if (overall_error_.ok()) { if (overall_error_.ok()) {
overall_error_ = overall_error_ = GRPC_ERROR_CREATE("Failed HTTP/1 client request");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed HTTP/1 client request");
} }
const grpc_resolved_address* addr = &addresses_[next_address_ - 1]; const grpc_resolved_address* addr = &addresses_[next_address_ - 1];
auto addr_text = grpc_sockaddr_to_uri(addr); auto addr_text = grpc_sockaddr_to_uri(addr);
@ -267,8 +264,8 @@ void HttpRequest::OnReadInternal(grpc_error_handle error) {
} }
} }
if (cancelled_) { if (cancelled_) {
Finish(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( Finish(GRPC_ERROR_CREATE_REFERENCING("HTTP1 request cancelled during read",
"HTTP1 request cancelled during read", &overall_error_, 1)); &overall_error_, 1));
} else if (error.ok()) { } else if (error.ok()) {
DoRead(); DoRead();
} else if (!have_read_byte_) { } else if (!have_read_byte_) {
@ -318,8 +315,8 @@ void HttpRequest::OnHandshakeDone(void* arg, grpc_error_handle error) {
req->ep_ = args->endpoint; req->ep_ = args->endpoint;
req->handshake_mgr_.reset(); req->handshake_mgr_.reset();
if (req->cancelled_) { if (req->cancelled_) {
req->NextAddress(GRPC_ERROR_CREATE_FROM_STATIC_STRING( req->NextAddress(
"HTTP request cancelled during handshake")); GRPC_ERROR_CREATE("HTTP request cancelled during handshake"));
return; return;
} }
req->StartWrite(); req->StartWrite();
@ -332,14 +329,14 @@ void HttpRequest::DoHandshake(const grpc_resolved_address* addr) {
channel_creds_->create_security_connector( channel_creds_->create_security_connector(
nullptr /*call_creds*/, uri_.authority().c_str(), &args); nullptr /*call_creds*/, uri_.authority().c_str(), &args);
if (sc == nullptr) { if (sc == nullptr) {
Finish(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( Finish(GRPC_ERROR_CREATE_REFERENCING("failed to create security connector",
"failed to create security connector", &overall_error_, 1)); &overall_error_, 1));
return; return;
} }
absl::StatusOr<std::string> address = grpc_sockaddr_to_uri(addr); absl::StatusOr<std::string> address = grpc_sockaddr_to_uri(addr);
if (!address.ok()) { if (!address.ok()) {
Finish(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( Finish(GRPC_ERROR_CREATE_REFERENCING("Failed to extract URI from address",
"Failed to extract URI from address", &overall_error_, 1)); &overall_error_, 1));
return; return;
} }
args = args.SetObject(std::move(sc)) args = args.SetObject(std::move(sc))
@ -362,13 +359,13 @@ void HttpRequest::NextAddress(grpc_error_handle error) {
AppendError(error); AppendError(error);
} }
if (cancelled_) { if (cancelled_) {
Finish(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( Finish(GRPC_ERROR_CREATE_REFERENCING("HTTP request was cancelled",
"HTTP request was cancelled", &overall_error_, 1)); &overall_error_, 1));
return; return;
} }
if (next_address_ == addresses_.size()) { if (next_address_ == addresses_.size()) {
Finish(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( Finish(GRPC_ERROR_CREATE_REFERENCING("Failed HTTP requests to all targets",
"Failed HTTP requests to all targets", &overall_error_, 1)); &overall_error_, 1));
return; return;
} }
const grpc_resolved_address* addr = &addresses_[next_address_++]; const grpc_resolved_address* addr = &addresses_[next_address_++];
@ -381,8 +378,7 @@ void HttpRequest::OnResolved(
MutexLock lock(&mu_); MutexLock lock(&mu_);
dns_request_handle_.reset(); dns_request_handle_.reset();
if (cancelled_) { if (cancelled_) {
Finish(GRPC_ERROR_CREATE_FROM_STATIC_STRING( Finish(GRPC_ERROR_CREATE("cancelled during DNS resolution"));
"cancelled during DNS resolution"));
return; return;
} }
if (!addresses_or.ok()) { if (!addresses_or.ok()) {

@ -114,8 +114,8 @@ class grpc_httpcli_ssl_channel_security_connector final
/* Check the peer name. */ /* Check the peer name. */
if (secure_peer_name_ != nullptr && if (secure_peer_name_ != nullptr &&
!tsi_ssl_peer_matches_name(&peer, secure_peer_name_)) { !tsi_ssl_peer_matches_name(&peer, secure_peer_name_)) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( error = GRPC_ERROR_CREATE(absl::StrCat("Peer name ", secure_peer_name_,
"Peer name ", secure_peer_name_, " is not in peer certificate")); " is not in peer certificate"));
} }
ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, error); ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, error);
tsi_peer_destruct(&peer); tsi_peer_destruct(&peer);

@ -44,46 +44,45 @@ static grpc_error_handle handle_response_line(grpc_http_parser* parser) {
uint8_t* end = beg + parser->cur_line_length; uint8_t* end = beg + parser->cur_line_length;
if (cur == end || *cur++ != 'H') { if (cur == end || *cur++ != 'H') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'H'"); return GRPC_ERROR_CREATE("Expected 'H'");
} }
if (cur == end || *cur++ != 'T') { if (cur == end || *cur++ != 'T') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'T'"); return GRPC_ERROR_CREATE("Expected 'T'");
} }
if (cur == end || *cur++ != 'T') { if (cur == end || *cur++ != 'T') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'T'"); return GRPC_ERROR_CREATE("Expected 'T'");
} }
if (cur == end || *cur++ != 'P') { if (cur == end || *cur++ != 'P') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'P'"); return GRPC_ERROR_CREATE("Expected 'P'");
} }
if (cur == end || *cur++ != '/') { if (cur == end || *cur++ != '/') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected '/'"); return GRPC_ERROR_CREATE("Expected '/'");
} }
if (cur == end || *cur++ != '1') { if (cur == end || *cur++ != '1') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected '1'"); return GRPC_ERROR_CREATE("Expected '1'");
} }
if (cur == end || *cur++ != '.') { if (cur == end || *cur++ != '.') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected '.'"); return GRPC_ERROR_CREATE("Expected '.'");
} }
if (cur == end || *cur < '0' || *cur++ > '1') { if (cur == end || *cur < '0' || *cur++ > '1') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Expected HTTP/1.0 or HTTP/1.1");
"Expected HTTP/1.0 or HTTP/1.1");
} }
if (cur == end || *cur++ != ' ') { if (cur == end || *cur++ != ' ') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected ' '"); return GRPC_ERROR_CREATE("Expected ' '");
} }
if (cur == end || *cur < '1' || *cur++ > '9') { if (cur == end || *cur < '1' || *cur++ > '9') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected status code"); return GRPC_ERROR_CREATE("Expected status code");
} }
if (cur == end || *cur < '0' || *cur++ > '9') { if (cur == end || *cur < '0' || *cur++ > '9') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected status code"); return GRPC_ERROR_CREATE("Expected status code");
} }
if (cur == end || *cur < '0' || *cur++ > '9') { if (cur == end || *cur < '0' || *cur++ > '9') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected status code"); return GRPC_ERROR_CREATE("Expected status code");
} }
parser->http.response->status = parser->http.response->status =
(cur[-3] - '0') * 100 + (cur[-2] - '0') * 10 + (cur[-1] - '0'); (cur[-3] - '0') * 100 + (cur[-2] - '0') * 10 + (cur[-1] - '0');
if (cur == end || *cur++ != ' ') { if (cur == end || *cur++ != ' ') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected ' '"); return GRPC_ERROR_CREATE("Expected ' '");
} }
/* we don't really care about the status code message */ /* we don't really care about the status code message */
@ -101,8 +100,7 @@ static grpc_error_handle handle_request_line(grpc_http_parser* parser) {
while (cur != end && *cur++ != ' ') { while (cur != end && *cur++ != ' ') {
} }
if (cur == end) { if (cur == end) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("No method on HTTP request line");
"No method on HTTP request line");
} }
parser->http.request->method = parser->http.request->method =
buf2str(beg, static_cast<size_t>(cur - beg - 1)); buf2str(beg, static_cast<size_t>(cur - beg - 1));
@ -111,30 +109,29 @@ static grpc_error_handle handle_request_line(grpc_http_parser* parser) {
while (cur != end && *cur++ != ' ') { while (cur != end && *cur++ != ' ') {
} }
if (cur == end) { if (cur == end) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No path on HTTP request line"); return GRPC_ERROR_CREATE("No path on HTTP request line");
} }
parser->http.request->path = buf2str(beg, static_cast<size_t>(cur - beg - 1)); parser->http.request->path = buf2str(beg, static_cast<size_t>(cur - beg - 1));
if (cur == end || *cur++ != 'H') { if (cur == end || *cur++ != 'H') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'H'"); return GRPC_ERROR_CREATE("Expected 'H'");
} }
if (cur == end || *cur++ != 'T') { if (cur == end || *cur++ != 'T') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'T'"); return GRPC_ERROR_CREATE("Expected 'T'");
} }
if (cur == end || *cur++ != 'T') { if (cur == end || *cur++ != 'T') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'T'"); return GRPC_ERROR_CREATE("Expected 'T'");
} }
if (cur == end || *cur++ != 'P') { if (cur == end || *cur++ != 'P') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected 'P'"); return GRPC_ERROR_CREATE("Expected 'P'");
} }
if (cur == end || *cur++ != '/') { if (cur == end || *cur++ != '/') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Expected '/'"); return GRPC_ERROR_CREATE("Expected '/'");
} }
vers_major = static_cast<uint8_t>(*cur++ - '1' + 1); vers_major = static_cast<uint8_t>(*cur++ - '1' + 1);
++cur; ++cur;
if (cur == end) { if (cur == end) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("End of line in HTTP version string");
"End of line in HTTP version string");
} }
vers_minor = static_cast<uint8_t>(*cur++ - '1' + 1); vers_minor = static_cast<uint8_t>(*cur++ - '1' + 1);
@ -144,19 +141,18 @@ static grpc_error_handle handle_request_line(grpc_http_parser* parser) {
} else if (vers_minor == 1) { } else if (vers_minor == 1) {
parser->http.request->version = GRPC_HTTP_HTTP11; parser->http.request->version = GRPC_HTTP_HTTP11;
} else { } else {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0"); "Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0");
} }
} else if (vers_major == 2) { } else if (vers_major == 2) {
if (vers_minor == 0) { if (vers_minor == 0) {
parser->http.request->version = GRPC_HTTP_HTTP20; parser->http.request->version = GRPC_HTTP_HTTP20;
} else { } else {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0"); "Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0");
} }
} else { } else {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0");
"Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0");
} }
return absl::OkStatus(); return absl::OkStatus();
@ -169,8 +165,7 @@ static grpc_error_handle handle_first_line(grpc_http_parser* parser) {
case GRPC_HTTP_RESPONSE: case GRPC_HTTP_RESPONSE:
return handle_response_line(parser); return handle_response_line(parser);
} }
GPR_UNREACHABLE_CODE( GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"));
} }
static grpc_error_handle add_header(grpc_http_parser* parser) { static grpc_error_handle add_header(grpc_http_parser* parser) {
@ -186,8 +181,7 @@ static grpc_error_handle add_header(grpc_http_parser* parser) {
GPR_ASSERT(cur != end); GPR_ASSERT(cur != end);
if (*cur == ' ' || *cur == '\t') { if (*cur == ' ' || *cur == '\t') {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE("Continued header lines not supported yet");
"Continued header lines not supported yet");
goto done; goto done;
} }
@ -195,8 +189,7 @@ static grpc_error_handle add_header(grpc_http_parser* parser) {
cur++; cur++;
} }
if (cur == end) { if (cur == end) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE("Didn't find ':' in header string");
"Didn't find ':' in header string");
goto done; goto done;
} }
GPR_ASSERT(cur >= beg); GPR_ASSERT(cur >= beg);
@ -272,8 +265,7 @@ static grpc_error_handle finish_line(grpc_http_parser* parser,
break; break;
case GRPC_HTTP_BODY: case GRPC_HTTP_BODY:
case GRPC_HTTP_END: case GRPC_HTTP_END:
GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE_FROM_STATIC_STRING( GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
"Should never reach here"));
} }
parser->cur_line_length = 0; parser->cur_line_length = 0;
@ -300,8 +292,7 @@ static grpc_error_handle addbyte_body(grpc_http_parser* parser, uint8_t byte) {
parser->http.response->chunk_length *= 16; parser->http.response->chunk_length *= 16;
parser->http.response->chunk_length += byte - 'A' + 10; parser->http.response->chunk_length += byte - 'A' + 10;
} else { } else {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Expected chunk size in hexadecimal");
"Expected chunk size in hexadecimal");
} }
return absl::OkStatus(); return absl::OkStatus();
case GRPC_HTTP_CHUNKED_IGNORE_ALL_UNTIL_LF: case GRPC_HTTP_CHUNKED_IGNORE_ALL_UNTIL_LF:
@ -316,8 +307,7 @@ static grpc_error_handle addbyte_body(grpc_http_parser* parser, uint8_t byte) {
case GRPC_HTTP_CHUNKED_BODY: case GRPC_HTTP_CHUNKED_BODY:
if (parser->http.response->chunk_length == 0) { if (parser->http.response->chunk_length == 0) {
if (byte != '\r') { if (byte != '\r') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Expected '\\r\\n' after chunk body");
"Expected '\\r\\n' after chunk body");
} }
parser->http.response->chunked_state = GRPC_HTTP_CHUNKED_CONSUME_LF; parser->http.response->chunked_state = GRPC_HTTP_CHUNKED_CONSUME_LF;
parser->http.response->chunk_length = 0; parser->http.response->chunk_length = 0;
@ -329,8 +319,7 @@ static grpc_error_handle addbyte_body(grpc_http_parser* parser, uint8_t byte) {
break; break;
case GRPC_HTTP_CHUNKED_CONSUME_LF: case GRPC_HTTP_CHUNKED_CONSUME_LF:
if (byte != '\n') { if (byte != '\n') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Expected '\\r\\n' after chunk body");
"Expected '\\r\\n' after chunk body");
} }
parser->http.response->chunked_state = GRPC_HTTP_CHUNKED_LENGTH; parser->http.response->chunked_state = GRPC_HTTP_CHUNKED_LENGTH;
return absl::OkStatus(); return absl::OkStatus();
@ -344,8 +333,7 @@ static grpc_error_handle addbyte_body(grpc_http_parser* parser, uint8_t byte) {
body_length = &parser->http.request->body_length; body_length = &parser->http.request->body_length;
body = &parser->http.request->body; body = &parser->http.request->body;
} else { } else {
GPR_UNREACHABLE_CODE( GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"));
} }
if (*body_length == parser->body_capacity) { if (*body_length == parser->body_capacity) {
@ -393,8 +381,7 @@ static grpc_error_handle addbyte(grpc_http_parser* parser, uint8_t byte,
gpr_log(GPR_ERROR, "HTTP header max line length (%d) exceeded", gpr_log(GPR_ERROR, "HTTP header max line length (%d) exceeded",
GRPC_HTTP_PARSER_MAX_HEADER_LENGTH); GRPC_HTTP_PARSER_MAX_HEADER_LENGTH);
} }
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("HTTP header max line length exceeded");
"HTTP header max line length exceeded");
} }
parser->cur_line[parser->cur_line_length] = byte; parser->cur_line[parser->cur_line_length] = byte;
parser->cur_line_length++; parser->cur_line_length++;
@ -405,7 +392,7 @@ static grpc_error_handle addbyte(grpc_http_parser* parser, uint8_t byte,
case GRPC_HTTP_BODY: case GRPC_HTTP_BODY:
return addbyte_body(parser, byte); return addbyte_body(parser, byte);
case GRPC_HTTP_END: case GRPC_HTTP_END:
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unexpected byte after end"); return GRPC_ERROR_CREATE("Unexpected byte after end");
} }
GPR_UNREACHABLE_CODE(return absl::OkStatus()); GPR_UNREACHABLE_CODE(return absl::OkStatus());
} }
@ -458,7 +445,7 @@ grpc_error_handle grpc_http_parser_parse(grpc_http_parser* parser,
grpc_error_handle grpc_http_parser_eof(grpc_http_parser* parser) { grpc_error_handle grpc_http_parser_eof(grpc_http_parser* parser) {
if ((parser->state != GRPC_HTTP_BODY) && (parser->state != GRPC_HTTP_END)) { if ((parser->state != GRPC_HTTP_BODY) && (parser->state != GRPC_HTTP_END)) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Did not finish headers"); return GRPC_ERROR_CREATE("Did not finish headers");
} }
return absl::OkStatus(); return absl::OkStatus();
} }

@ -168,15 +168,14 @@ static void ReadAction(void* arg, grpc_error_handle error) {
GRPC_ERROR_CREATE_FROM_CFERROR(stream_error, "Read error"), ep); GRPC_ERROR_CREATE_FROM_CFERROR(stream_error, "Read error"), ep);
CFRelease(stream_error); CFRelease(stream_error);
} else { } else {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Read error"); error = GRPC_ERROR_CREATE("Read error");
} }
CallReadCb(ep, error); CallReadCb(ep, error);
EP_UNREF(ep, "read"); EP_UNREF(ep, "read");
} else if (read_size == 0) { } else if (read_size == 0) {
grpc_slice_buffer_reset_and_unref(ep->read_slices); grpc_slice_buffer_reset_and_unref(ep->read_slices);
CallReadCb(ep, CallReadCb(ep,
CFStreamAnnotateError( CFStreamAnnotateError(GRPC_ERROR_CREATE("Socket closed"), ep));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), ep));
EP_UNREF(ep, "read"); EP_UNREF(ep, "read");
} else { } else {
if (read_size < static_cast<CFIndex>(len)) { if (read_size < static_cast<CFIndex>(len)) {
@ -208,7 +207,7 @@ static void WriteAction(void* arg, grpc_error_handle error) {
GRPC_ERROR_CREATE_FROM_CFERROR(stream_error, "write failed."), ep); GRPC_ERROR_CREATE_FROM_CFERROR(stream_error, "write failed."), ep);
CFRelease(stream_error); CFRelease(stream_error);
} else { } else {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("write failed."); error = GRPC_ERROR_CREATE("write failed.");
} }
CallWriteCb(ep, error); CallWriteCb(ep, error);
EP_UNREF(ep, "write"); EP_UNREF(ep, "write");

@ -148,29 +148,35 @@ void grpc_enable_error_creation();
#define GRPC_ERROR_IS_NONE(err) (err).ok() #define GRPC_ERROR_IS_NONE(err) (err).ok()
#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc) \ #define GRPC_ERROR_CREATE(desc) \
StatusCreate(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {})
#define GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc) \
StatusCreate(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {})
#define GRPC_ERROR_CREATE_FROM_CPP_STRING(desc) \
StatusCreate(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {})
#define GRPC_ERROR_CREATE_FROM_STRING_VIEW(desc) \
StatusCreate(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {}) StatusCreate(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, {})
// Deprecated: Please do not use these macros. begin
// TODO(veblush): Remove this once migration is done.
#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc) GRPC_ERROR_CREATE(desc)
#define GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc) GRPC_ERROR_CREATE(desc)
#define GRPC_ERROR_CREATE_FROM_CPP_STRING(desc) GRPC_ERROR_CREATE(desc)
#define GRPC_ERROR_CREATE_FROM_STRING_VIEW(desc) GRPC_ERROR_CREATE(desc)
// Deprecated: end
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,
size_t children_count, size_t children_count,
absl::Status* children) GRPC_MUST_USE_RESULT; absl::Status* children) GRPC_MUST_USE_RESULT;
// Create an error that references some other errors. This function adds a // Create an error that references some other errors.
// reference to each error in errs - it does not consume an existing reference #define GRPC_ERROR_CREATE_REFERENCING(desc, errs, count) \
#define GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(desc, errs, count) \
grpc_status_create(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, count, \
errs)
#define GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(desc, errs, count) \
grpc_status_create(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, count, \ grpc_status_create(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, count, \
errs) errs)
// Deprecated: Please do not use these macros. begin
// TODO(veblush): Remove this once migration is done.
#define GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(desc, errs, count) \
GRPC_ERROR_CREATE_REFERENCING(desc, errs, count)
#define GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(desc, errs, count) \
GRPC_ERROR_CREATE_REFERENCING(desc, errs, count)
// Deprecated: end
// Consumes all the errors in the vector and forms a referencing error from // Consumes all the errors in the vector and forms a referencing error from
// them. If the vector is empty, return absl::OkStatus(). // them. If the vector is empty, return absl::OkStatus().
template <typename VectorType> template <typename VectorType>
@ -188,8 +194,12 @@ static absl::Status grpc_status_create_from_vector(
#define GRPC_ERROR_CREATE_FROM_VECTOR(desc, error_list) \ #define GRPC_ERROR_CREATE_FROM_VECTOR(desc, error_list) \
grpc_status_create_from_vector(DEBUG_LOCATION, desc, error_list) grpc_status_create_from_vector(DEBUG_LOCATION, desc, error_list)
// Deprecated: Please do not use these macros. begin
// TODO(veblush): Remove this once migration is done.
#define GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING(desc, error_list) \ #define GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING(desc, error_list) \
grpc_status_create_from_vector(DEBUG_LOCATION, desc, error_list) GRPC_ERROR_CREATE_FROM_VECTOR(desc, error_list)
// Deprecated: end
absl::Status grpc_os_error(const grpc_core::DebugLocation& location, int err, absl::Status grpc_os_error(const grpc_core::DebugLocation& location, int err,
const char* call_name) GRPC_MUST_USE_RESULT; const char* call_name) GRPC_MUST_USE_RESULT;

@ -243,7 +243,7 @@ static bool append_error(grpc_error_handle* composite, grpc_error_handle error,
const char* desc) { const char* desc) {
if (error.ok()) return true; if (error.ok()) return true;
if (composite->ok()) { if (composite->ok()) {
*composite = GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc); *composite = GRPC_ERROR_CREATE(desc);
} }
*composite = grpc_error_add_child(*composite, error); *composite = grpc_error_add_child(*composite, error);
return false; return false;
@ -411,8 +411,7 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
bool is_release_fd = (release_fd != nullptr); bool is_release_fd = (release_fd != nullptr);
if (!fd->read_closure->IsShutdown()) { if (!fd->read_closure->IsShutdown()) {
fd_shutdown_internal(fd, GRPC_ERROR_CREATE_FROM_COPIED_STRING(reason), fd_shutdown_internal(fd, GRPC_ERROR_CREATE(reason), is_release_fd);
is_release_fd);
} }
/* If release_fd is not NULL, we should be relinquishing control of the file /* If release_fd is not NULL, we should be relinquishing control of the file

@ -491,10 +491,9 @@ static grpc_error_handle fd_shutdown_error(grpc_fd* fd) {
if (!fd->shutdown) { if (!fd->shutdown) {
return absl::OkStatus(); return absl::OkStatus();
} else { } else {
return grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( return grpc_error_set_int(
"FD shutdown", &fd->shutdown_error, 1), GRPC_ERROR_CREATE_REFERENCING("FD shutdown", &fd->shutdown_error, 1),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE);
GRPC_STATUS_UNAVAILABLE);
} }
} }
@ -503,7 +502,7 @@ static void notify_on_locked(grpc_fd* fd, grpc_closure** st,
if (fd->shutdown || gpr_atm_no_barrier_load(&fd->pollhup)) { if (fd->shutdown || gpr_atm_no_barrier_load(&fd->pollhup)) {
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, closure, DEBUG_LOCATION, closure,
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("FD shutdown"), grpc_error_set_int(GRPC_ERROR_CREATE("FD shutdown"),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,
GRPC_STATUS_UNAVAILABLE)); GRPC_STATUS_UNAVAILABLE));
} else if (*st == CLOSURE_NOT_READY) { } else if (*st == CLOSURE_NOT_READY) {
@ -756,7 +755,7 @@ static void kick_append_error(grpc_error_handle* composite,
grpc_error_handle error) { grpc_error_handle error) {
if (error.ok()) return; if (error.ok()) return;
if (composite->ok()) { if (composite->ok()) {
*composite = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Kick Failure"); *composite = GRPC_ERROR_CREATE("Kick Failure");
} }
*composite = grpc_error_add_child(*composite, error); *composite = grpc_error_add_child(*composite, error);
} }
@ -892,7 +891,7 @@ static void work_combine_error(grpc_error_handle* composite,
grpc_error_handle error) { grpc_error_handle error) {
if (error.ok()) return; if (error.ok()) return;
if (composite->ok()) { if (composite->ok()) {
*composite = GRPC_ERROR_CREATE_FROM_STATIC_STRING("pollset_work"); *composite = GRPC_ERROR_CREATE("pollset_work");
} }
*composite = grpc_error_add_child(*composite, error); *composite = grpc_error_add_child(*composite, error);
} }

@ -67,10 +67,9 @@ end:
*output = result; *output = result;
if (file != nullptr) fclose(file); if (file != nullptr) fclose(file);
if (!error.ok()) { if (!error.ok()) {
grpc_error_handle error_out = grpc_error_handle error_out = grpc_error_set_str(
grpc_error_set_str(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( GRPC_ERROR_CREATE_REFERENCING("Failed to load file", &error, 1),
"Failed to load file", &error, 1), grpc_core::StatusStrProperty::kFilename, filename);
grpc_core::StatusStrProperty::kFilename, filename);
error = error_out; error = error_out;
} }
GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX;

@ -141,9 +141,9 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) {
if ((curr & kShutdownBit) > 0) { if ((curr & kShutdownBit) > 0) {
grpc_error_handle shutdown_err = grpc_error_handle shutdown_err =
internal::StatusGetFromHeapPtr(curr & ~kShutdownBit); internal::StatusGetFromHeapPtr(curr & ~kShutdownBit);
ExecCtx::Run(DEBUG_LOCATION, closure, ExecCtx::Run(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( DEBUG_LOCATION, closure,
"FD Shutdown", &shutdown_err, 1)); GRPC_ERROR_CREATE_REFERENCING("FD Shutdown", &shutdown_err, 1));
return; return;
} }
@ -195,9 +195,9 @@ bool LockfreeEvent::SetShutdown(grpc_error_handle shutdown_error) {
happens-after on that edge), and a release to pair with anything happens-after on that edge), and a release to pair with anything
loading the shutdown state. */ loading the shutdown state. */
if (gpr_atm_full_cas(&state_, curr, new_state)) { if (gpr_atm_full_cas(&state_, curr, new_state)) {
ExecCtx::Run(DEBUG_LOCATION, reinterpret_cast<grpc_closure*>(curr), ExecCtx::Run(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( DEBUG_LOCATION, reinterpret_cast<grpc_closure*>(curr),
"FD Shutdown", &shutdown_error, 1)); GRPC_ERROR_CREATE_REFERENCING("FD Shutdown", &shutdown_error, 1));
return true; return true;
} }

@ -31,7 +31,7 @@
// because Cython doesn't handle #defines well. // because Cython doesn't handle #defines well.
inline grpc_error_handle grpc_socket_error(char* error) { inline grpc_error_handle grpc_socket_error(char* error) {
return grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(error), return grpc_error_set_int(GRPC_ERROR_CREATE(error),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,
GRPC_STATUS_UNAVAILABLE); GRPC_STATUS_UNAVAILABLE);
} }

@ -105,16 +105,14 @@ NativeDNSResolver::LookupHostnameBlocking(absl::string_view name,
// parse name, splitting it into host and port parts // parse name, splitting it into host and port parts
SplitHostPort(name, &host, &port); SplitHostPort(name, &host, &port);
if (host.empty()) { if (host.empty()) {
err = grpc_error_set_str( err = grpc_error_set_str(GRPC_ERROR_CREATE("unparseable host:port"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"), StatusStrProperty::kTargetAddress, name);
StatusStrProperty::kTargetAddress, name);
goto done; goto done;
} }
if (port.empty()) { if (port.empty()) {
if (default_port.empty()) { if (default_port.empty()) {
err = grpc_error_set_str( err = grpc_error_set_str(GRPC_ERROR_CREATE("no port in name"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("no port in name"), StatusStrProperty::kTargetAddress, name);
StatusStrProperty::kTargetAddress, name);
goto done; goto done;
} }
port = std::string(default_port); port = std::string(default_port);
@ -143,9 +141,8 @@ NativeDNSResolver::LookupHostnameBlocking(absl::string_view name,
err = grpc_error_set_str( err = grpc_error_set_str(
grpc_error_set_str( grpc_error_set_str(
grpc_error_set_str( grpc_error_set_str(
grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE(gai_strerror(s)),
GRPC_ERROR_CREATE_FROM_STATIC_STRING(gai_strerror(s)), StatusIntProperty::kErrorNo, s),
StatusIntProperty::kErrorNo, s),
StatusStrProperty::kOsError, gai_strerror(s)), StatusStrProperty::kOsError, gai_strerror(s)),
StatusStrProperty::kSyscall, "getaddrinfo"), StatusStrProperty::kSyscall, "getaddrinfo"),
StatusStrProperty::kTargetAddress, name); StatusStrProperty::kTargetAddress, name);

@ -111,14 +111,13 @@ NativeDNSResolver::LookupHostnameBlocking(absl::string_view name,
std::string port; std::string port;
SplitHostPort(name, &host, &port); SplitHostPort(name, &host, &port);
if (host.empty()) { if (host.empty()) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING( error =
absl::StrFormat("unparseable host:port: '%s'", name)); GRPC_ERROR_CREATE(absl::StrFormat("unparseable host:port: '%s'", name));
goto done; goto done;
} }
if (port.empty()) { if (port.empty()) {
if (default_port.empty()) { if (default_port.empty()) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING( error = GRPC_ERROR_CREATE(absl::StrFormat("no port in name '%s'", name));
absl::StrFormat("no port in name '%s'", name));
goto done; goto done;
} }
port = std::string(default_port); port = std::string(default_port);

@ -100,7 +100,7 @@ grpc_error_handle grpc_set_socket_no_sigpipe_if_possible(int fd) {
return GRPC_OS_ERROR(errno, "getsockopt(SO_NOSIGPIPE)"); return GRPC_OS_ERROR(errno, "getsockopt(SO_NOSIGPIPE)");
} }
if ((newval != 0) != (val != 0)) { if ((newval != 0) != (val != 0)) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_NOSIGPIPE"); return GRPC_ERROR_CREATE("Failed to set SO_NOSIGPIPE");
} }
#else #else
// Avoid unused parameter warning for conditional parameter // Avoid unused parameter warning for conditional parameter
@ -181,7 +181,7 @@ grpc_error_handle grpc_set_socket_reuse_addr(int fd, int reuse) {
return GRPC_OS_ERROR(errno, "getsockopt(SO_REUSEADDR)"); return GRPC_OS_ERROR(errno, "getsockopt(SO_REUSEADDR)");
} }
if ((newval != 0) != val) { if ((newval != 0) != val) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_REUSEADDR"); return GRPC_ERROR_CREATE("Failed to set SO_REUSEADDR");
} }
return absl::OkStatus(); return absl::OkStatus();
@ -190,8 +190,7 @@ grpc_error_handle grpc_set_socket_reuse_addr(int fd, int reuse) {
/* set a socket to reuse old addresses */ /* set a socket to reuse old addresses */
grpc_error_handle grpc_set_socket_reuse_port(int fd, int reuse) { grpc_error_handle grpc_set_socket_reuse_port(int fd, int reuse) {
#ifndef SO_REUSEPORT #ifndef SO_REUSEPORT
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("SO_REUSEPORT unavailable on compiling system");
"SO_REUSEPORT unavailable on compiling system");
#else #else
int val = (reuse != 0); int val = (reuse != 0);
int newval; int newval;
@ -203,7 +202,7 @@ grpc_error_handle grpc_set_socket_reuse_port(int fd, int reuse) {
return GRPC_OS_ERROR(errno, "getsockopt(SO_REUSEPORT)"); return GRPC_OS_ERROR(errno, "getsockopt(SO_REUSEPORT)");
} }
if ((newval != 0) != val) { if ((newval != 0) != val) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_REUSEPORT"); return GRPC_ERROR_CREATE("Failed to set SO_REUSEPORT");
} }
return absl::OkStatus(); return absl::OkStatus();
@ -244,7 +243,7 @@ grpc_error_handle grpc_set_socket_low_latency(int fd, int low_latency) {
return GRPC_OS_ERROR(errno, "getsockopt(TCP_NODELAY)"); return GRPC_OS_ERROR(errno, "getsockopt(TCP_NODELAY)");
} }
if ((newval != 0) != val) { if ((newval != 0) != val) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set TCP_NODELAY"); return GRPC_ERROR_CREATE("Failed to set TCP_NODELAY");
} }
return absl::OkStatus(); return absl::OkStatus();
} }
@ -376,7 +375,7 @@ grpc_error_handle grpc_set_socket_with_mutator(int fd, grpc_fd_usage usage,
grpc_socket_mutator* mutator) { grpc_socket_mutator* mutator) {
GPR_ASSERT(mutator); GPR_ASSERT(mutator);
if (!grpc_socket_mutator_mutate_fd(mutator, fd, usage)) { if (!grpc_socket_mutator_mutate_fd(mutator, fd, usage)) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("grpc_socket_mutator failed."); return GRPC_ERROR_CREATE("grpc_socket_mutator failed.");
} }
return absl::OkStatus(); return absl::OkStatus();
} }

@ -90,8 +90,7 @@ static void OnAlarm(void* arg, grpc_error_handle error) {
if (done) { if (done) {
CFStreamConnectCleanup(connect); CFStreamConnectCleanup(connect);
} else { } else {
grpc_error_handle error = grpc_error_handle error = GRPC_ERROR_CREATE("connect() timed out");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("connect() timed out");
grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, error); grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, error);
} }
} }
@ -154,8 +153,7 @@ static int64_t CFStreamClientConnect(
const grpc_resolved_address* resolved_addr, grpc_core::Timestamp deadline) { const grpc_resolved_address* resolved_addr, grpc_core::Timestamp deadline) {
auto addr_uri = grpc_sockaddr_to_uri(resolved_addr); auto addr_uri = grpc_sockaddr_to_uri(resolved_addr);
if (!addr_uri.ok()) { if (!addr_uri.ok()) {
grpc_error_handle error = grpc_error_handle error = GRPC_ERROR_CREATE(addr_uri.status().ToString());
GRPC_ERROR_CREATE_FROM_CPP_STRING(addr_uri.status().ToString());
grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, error); grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, error);
return 0; return 0;
} }

@ -136,8 +136,7 @@ static void tc_on_alarm(void* acp, grpc_error_handle error) {
} }
gpr_mu_lock(&ac->mu); gpr_mu_lock(&ac->mu);
if (ac->fd != nullptr) { if (ac->fd != nullptr) {
grpc_fd_shutdown( grpc_fd_shutdown(ac->fd, GRPC_ERROR_CREATE("connect() timed out"));
ac->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("connect() timed out"));
} }
done = (--ac->refs == 0); done = (--ac->refs == 0);
gpr_mu_unlock(&ac->mu); gpr_mu_unlock(&ac->mu);
@ -328,8 +327,7 @@ int64_t grpc_tcp_client_create_from_prepared_fd(
auto addr_uri = grpc_sockaddr_to_uri(addr); auto addr_uri = grpc_sockaddr_to_uri(addr);
if (!addr_uri.ok()) { if (!addr_uri.ok()) {
grpc_error_handle error = grpc_error_handle error = GRPC_ERROR_CREATE(addr_uri.status().ToString());
GRPC_ERROR_CREATE_FROM_CPP_STRING(addr_uri.status().ToString());
grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, error); grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, error);
return 0; return 0;
} }

@ -108,7 +108,7 @@ static void on_connect(void* acp, grpc_error_handle error) {
socket = nullptr; socket = nullptr;
} }
} else { } else {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("socket is null"); error = GRPC_ERROR_CREATE("socket is null");
} }
} }
@ -141,7 +141,7 @@ static int64_t tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint,
addr_uri = grpc_sockaddr_to_uri(addr); addr_uri = grpc_sockaddr_to_uri(addr);
if (!addr_uri.ok()) { if (!addr_uri.ok()) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING(addr_uri.status().ToString()); error = GRPC_ERROR_CREATE(addr_uri.status().ToString());
goto failure; goto failure;
} }
@ -219,8 +219,7 @@ static int64_t tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint,
failure: failure:
GPR_ASSERT(!error.ok()); GPR_ASSERT(!error.ok());
grpc_error_handle final_error = grpc_error_set_str( grpc_error_handle final_error = grpc_error_set_str(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Failed to connect", GRPC_ERROR_CREATE_REFERENCING("Failed to connect", &error, 1),
&error, 1),
grpc_core::StatusStrProperty::kTargetAddress, grpc_core::StatusStrProperty::kTargetAddress,
addr_uri.ok() ? *addr_uri : addr_uri.status().ToString()); addr_uri.ok() ? *addr_uri : addr_uri.status().ToString());
if (socket != NULL) { if (socket != NULL) {

@ -736,9 +736,8 @@ static void tcp_free(grpc_tcp* tcp) {
grpc_slice_buffer_destroy(&tcp->last_read_buffer); grpc_slice_buffer_destroy(&tcp->last_read_buffer);
/* The lock is not really necessary here, since all refs have been released */ /* The lock is not really necessary here, since all refs have been released */
gpr_mu_lock(&tcp->tb_mu); gpr_mu_lock(&tcp->tb_mu);
grpc_core::TracedBuffer::Shutdown( grpc_core::TracedBuffer::Shutdown(&tcp->tb_head, tcp->outgoing_buffer_arg,
&tcp->tb_head, tcp->outgoing_buffer_arg, GRPC_ERROR_CREATE("endpoint destroyed"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("endpoint destroyed"));
gpr_mu_unlock(&tcp->tb_mu); gpr_mu_unlock(&tcp->tb_mu);
tcp->outgoing_buffer_arg = nullptr; tcp->outgoing_buffer_arg = nullptr;
gpr_mu_destroy(&tcp->tb_mu); gpr_mu_destroy(&tcp->tb_mu);
@ -957,8 +956,7 @@ static bool tcp_do_read(grpc_tcp* tcp, grpc_error_handle* error)
* since the connection is closed we will drop the data here, because we * since the connection is closed we will drop the data here, because we
* can't call the callback multiple times. */ * can't call the callback multiple times. */
grpc_slice_buffer_reset_and_unref(tcp->incoming_buffer); grpc_slice_buffer_reset_and_unref(tcp->incoming_buffer);
*error = tcp_annotate_error( *error = tcp_annotate_error(GRPC_ERROR_CREATE("Socket closed"), tcp);
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp);
return true; return true;
} }
@ -1525,7 +1523,7 @@ void tcp_shutdown_buffer_list(grpc_tcp* tcp) {
gpr_mu_lock(&tcp->tb_mu); gpr_mu_lock(&tcp->tb_mu);
grpc_core::TracedBuffer::Shutdown( grpc_core::TracedBuffer::Shutdown(
&tcp->tb_head, tcp->outgoing_buffer_arg, &tcp->tb_head, tcp->outgoing_buffer_arg,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("TracedBuffer list shutdown")); GRPC_ERROR_CREATE("TracedBuffer list shutdown"));
gpr_mu_unlock(&tcp->tb_mu); gpr_mu_unlock(&tcp->tb_mu);
tcp->outgoing_buffer_arg = nullptr; tcp->outgoing_buffer_arg = nullptr;
} }
@ -1856,8 +1854,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
grpc_core::Closure::Run( grpc_core::Closure::Run(
DEBUG_LOCATION, cb, DEBUG_LOCATION, cb,
grpc_fd_is_shutdown(tcp->em_fd) grpc_fd_is_shutdown(tcp->em_fd)
? tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), ? tcp_annotate_error(GRPC_ERROR_CREATE("EOF"), tcp)
tcp)
: absl::OkStatus()); : absl::OkStatus());
tcp_shutdown_buffer_list(tcp); tcp_shutdown_buffer_list(tcp);
return; return;

@ -167,8 +167,7 @@ static void tcp_server_destroy(grpc_tcp_server* s) {
if (s->active_ports) { if (s->active_ports) {
grpc_tcp_listener* sp; grpc_tcp_listener* sp;
for (sp = s->head; sp; sp = sp->next) { for (sp = s->head; sp; sp = sp->next) {
grpc_fd_shutdown( grpc_fd_shutdown(sp->emfd, GRPC_ERROR_CREATE("Server destroyed"));
sp->emfd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server destroyed"));
} }
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);
} else { } else {
@ -350,8 +349,8 @@ static grpc_error_handle add_wildcard_addrs_to_server(grpc_tcp_server* s,
} }
return absl::OkStatus(); return absl::OkStatus();
} else { } else {
grpc_error_handle root_err = GRPC_ERROR_CREATE_FROM_STATIC_STRING( grpc_error_handle root_err =
"Failed to add any wildcard listeners"); GRPC_ERROR_CREATE("Failed to add any wildcard listeners");
GPR_ASSERT(!v6_err.ok() && !v4_err.ok()); GPR_ASSERT(!v6_err.ok() && !v4_err.ok());
root_err = grpc_error_add_child(root_err, v6_err); root_err = grpc_error_add_child(root_err, v6_err);
root_err = grpc_error_add_child(root_err, v4_err); root_err = grpc_error_add_child(root_err, v4_err);
@ -382,7 +381,7 @@ static grpc_error_handle clone_port(grpc_tcp_listener* listener,
listener->server->nports++; listener->server->nports++;
addr_str = grpc_sockaddr_to_string(&listener->addr, true); addr_str = grpc_sockaddr_to_string(&listener->addr, true);
if (!addr_str.ok()) { if (!addr_str.ok()) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(addr_str.status().ToString()); return GRPC_ERROR_CREATE(addr_str.status().ToString());
} }
sp = static_cast<grpc_tcp_listener*>(gpr_malloc(sizeof(grpc_tcp_listener))); sp = static_cast<grpc_tcp_listener*>(gpr_malloc(sizeof(grpc_tcp_listener)));
sp->next = listener->next; sp->next = listener->next;
@ -576,8 +575,7 @@ static void tcp_server_shutdown_listeners(grpc_tcp_server* s) {
if (s->active_ports) { if (s->active_ports) {
grpc_tcp_listener* sp; grpc_tcp_listener* sp;
for (sp = s->head; sp; sp = sp->next) { for (sp = s->head; sp; sp = sp->next) {
grpc_fd_shutdown(sp->emfd, grpc_fd_shutdown(sp->emfd, GRPC_ERROR_CREATE("Server shutdown"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"));
} }
} }
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);

@ -94,7 +94,7 @@ static grpc_error_handle add_socket_to_server(grpc_tcp_server* s, int fd,
GPR_ASSERT(port > 0); GPR_ASSERT(port > 0);
absl::StatusOr<std::string> addr_str = grpc_sockaddr_to_string(addr, true); absl::StatusOr<std::string> addr_str = grpc_sockaddr_to_string(addr, true);
if (!addr_str.ok()) { if (!addr_str.ok()) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(addr_str.status().ToString()); return GRPC_ERROR_CREATE(addr_str.status().ToString());
} }
std::string name = absl::StrCat("tcp-server-listener:", addr_str.value()); std::string name = absl::StrCat("tcp-server-listener:", addr_str.value());
gpr_mu_lock(&s->mu); gpr_mu_lock(&s->mu);
@ -215,10 +215,9 @@ error:
if (fd >= 0) { if (fd >= 0) {
close(fd); close(fd);
} }
grpc_error_handle ret = grpc_error_handle ret = grpc_error_set_int(
grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( GRPC_ERROR_CREATE_REFERENCING("Unable to configure socket", &err, 1),
"Unable to configure socket", &err, 1), grpc_core::StatusIntProperty::kFd, fd);
grpc_core::StatusIntProperty::kFd, fd);
return ret; return ret;
} }

@ -85,8 +85,7 @@ static grpc_error_handle get_unused_port(int* port) {
} }
close(fd); close(fd);
*port = grpc_sockaddr_get_port(&wild); *port = grpc_sockaddr_get_port(&wild);
return *port <= 0 ? GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad port") return *port <= 0 ? GRPC_ERROR_CREATE("Bad port") : absl::OkStatus();
: absl::OkStatus();
} }
grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
@ -106,7 +105,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
if ((err = get_unused_port(&requested_port)) != absl::OkStatus()) { if ((err = get_unused_port(&requested_port)) != absl::OkStatus()) {
return err; return err;
} else if (requested_port <= 0) { } else if (requested_port <= 0) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad get_unused_port()"); return GRPC_ERROR_CREATE("Bad get_unused_port()");
} }
gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port);
} }
@ -130,12 +129,12 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
memcpy(addr.addr, ifa_it->ifa_addr, addr.len); memcpy(addr.addr, ifa_it->ifa_addr, addr.len);
if (!grpc_sockaddr_set_port(&addr, requested_port)) { if (!grpc_sockaddr_set_port(&addr, requested_port)) {
/* Should never happen, because we check sa_family above. */ /* Should never happen, because we check sa_family above. */
err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set port"); err = GRPC_ERROR_CREATE("Failed to set port");
break; break;
} }
auto addr_str = grpc_sockaddr_to_string(&addr, false); auto addr_str = grpc_sockaddr_to_string(&addr, false);
if (!addr_str.ok()) { if (!addr_str.ok()) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(addr_str.status().ToString()); return GRPC_ERROR_CREATE(addr_str.status().ToString());
} }
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"Adding local addr from interface %s flags 0x%x to server: %s", "Adding local addr from interface %s flags 0x%x to server: %s",
@ -149,7 +148,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
} }
if ((err = grpc_tcp_server_add_addr(s, &addr, port_index, fd_index, &dsmode, if ((err = grpc_tcp_server_add_addr(s, &addr, port_index, fd_index, &dsmode,
&new_sp)) != absl::OkStatus()) { &new_sp)) != absl::OkStatus()) {
grpc_error_handle root_err = GRPC_ERROR_CREATE_FROM_CPP_STRING( grpc_error_handle root_err = GRPC_ERROR_CREATE(
absl::StrCat("Failed to add listener: ", addr_str.value())); absl::StrCat("Failed to add listener: ", addr_str.value()));
err = grpc_error_add_child(root_err, err); err = grpc_error_add_child(root_err, err);
break; break;
@ -167,7 +166,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
if (!err.ok()) { if (!err.ok()) {
return err; return err;
} else if (sp == nullptr) { } else if (sp == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No local addresses"); return GRPC_ERROR_CREATE("No local addresses");
} else { } else {
*out_port = sp->port; *out_port = sp->port;
return absl::OkStatus(); return absl::OkStatus();

@ -28,7 +28,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* /*s*/,
unsigned /*port_index*/, unsigned /*port_index*/,
int /*requested_port*/, int /*requested_port*/,
int* /*out_port*/) { int* /*out_port*/) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("no ifaddrs available"); return GRPC_ERROR_CREATE("no ifaddrs available");
} }
bool grpc_tcp_server_have_ifaddrs(void) { return false; } bool grpc_tcp_server_have_ifaddrs(void) { return false; }

@ -227,8 +227,8 @@ failure:
auto addr_uri = grpc_sockaddr_to_uri(addr); auto addr_uri = grpc_sockaddr_to_uri(addr);
grpc_error_set_int( grpc_error_set_int(
grpc_error_set_str( grpc_error_set_str(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( GRPC_ERROR_CREATE_REFERENCING("Failed to prepare server socket",
"Failed to prepare server socket", &error, 1), &error, 1),
grpc_core::StatusStrProperty::kTargetAddress, grpc_core::StatusStrProperty::kTargetAddress,
addr_uri.ok() ? *addr_uri : addr_uri.status().ToString()), addr_uri.ok() ? *addr_uri : addr_uri.status().ToString()),
grpc_core::StatusIntProperty::kFd, (intptr_t)sock); grpc_core::StatusIntProperty::kFd, (intptr_t)sock);
@ -510,9 +510,8 @@ done:
gpr_free(allocated_addr); gpr_free(allocated_addr);
if (!error.ok()) { if (!error.ok()) {
grpc_error_handle error_out = grpc_error_handle error_out = GRPC_ERROR_CREATE_REFERENCING(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failed to add port to server", &error, 1);
"Failed to add port to server", &error, 1);
error = error_out; error = error_out;
*port = -1; *port = -1;
} else { } else {

@ -186,7 +186,7 @@ static void on_read(void* tcpp, grpc_error_handle error) {
if (error.ok()) { if (error.ok()) {
if (info->wsa_error != 0 && !tcp->shutting_down) { if (info->wsa_error != 0 && !tcp->shutting_down) {
char* utf8_message = gpr_format_message(info->wsa_error); char* utf8_message = gpr_format_message(info->wsa_error);
error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(utf8_message); error = GRPC_ERROR_CREATE(utf8_message);
gpr_free(utf8_message); gpr_free(utf8_message);
grpc_slice_buffer_reset_and_unref(tcp->read_slices); grpc_slice_buffer_reset_and_unref(tcp->read_slices);
} else { } else {
@ -219,9 +219,9 @@ static void on_read(void* tcpp, grpc_error_handle error) {
grpc_slice_buffer_reset_and_unref(tcp->read_slices); grpc_slice_buffer_reset_and_unref(tcp->read_slices);
error = grpc_error_set_int( error = grpc_error_set_int(
tcp->shutting_down tcp->shutting_down
? GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( ? GRPC_ERROR_CREATE_REFERENCING("TCP stream shutting down",
"TCP stream shutting down", &tcp->shutdown_error, 1) &tcp->shutdown_error, 1)
: GRPC_ERROR_CREATE_FROM_STATIC_STRING("End of TCP stream"), : GRPC_ERROR_CREATE("End of TCP stream"),
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE); grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE);
} }
} }
@ -253,8 +253,8 @@ static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices,
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, cb, DEBUG_LOCATION, cb,
grpc_error_set_int( grpc_error_set_int(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( GRPC_ERROR_CREATE_REFERENCING("TCP socket is shutting down",
"TCP socket is shutting down", &tcp->shutdown_error, 1), &tcp->shutdown_error, 1),
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE)); grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE));
return; return;
} }
@ -367,8 +367,8 @@ static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices,
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, cb, DEBUG_LOCATION, cb,
grpc_error_set_int( grpc_error_set_int(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( GRPC_ERROR_CREATE_REFERENCING("TCP socket is shutting down",
"TCP socket is shutting down", &tcp->shutdown_error, 1), &tcp->shutdown_error, 1),
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE)); grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_UNAVAILABLE));
return; return;
} }

@ -273,9 +273,8 @@ static void timer_list_init() {
static void timer_list_shutdown() { static void timer_list_shutdown() {
size_t i; size_t i;
run_some_expired_timers( run_some_expired_timers(grpc_core::Timestamp::InfFuture(), nullptr,
grpc_core::Timestamp::InfFuture(), nullptr, GRPC_ERROR_CREATE("Timer list shutdown"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timer list shutdown"));
for (i = 0; i < g_num_shards; i++) { for (i = 0; i < g_num_shards; i++) {
timer_shard* shard = &g_shards[i]; timer_shard* shard = &g_shards[i];
gpr_mu_destroy(&shard->mu); gpr_mu_destroy(&shard->mu);
@ -350,8 +349,7 @@ static void timer_init(grpc_timer* timer, grpc_core::Timestamp deadline,
timer->pending = false; timer->pending = false;
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, timer->closure, DEBUG_LOCATION, timer->closure,
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("Attempt to create timer before initialization"));
"Attempt to create timer before initialization"));
return; return;
} }
@ -684,7 +682,7 @@ static grpc_timer_check_result timer_check(grpc_core::Timestamp* next) {
grpc_error_handle shutdown_error = grpc_error_handle shutdown_error =
now != grpc_core::Timestamp::InfFuture() now != grpc_core::Timestamp::InfFuture()
? absl::OkStatus() ? absl::OkStatus()
: GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutting down timer system"); : GRPC_ERROR_CREATE("Shutting down timer system");
// tracing // tracing
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {

@ -45,7 +45,7 @@ bool ExtractJsonBool(const Json& json, absl::string_view field_name,
*output = false; *output = false;
return true; return true;
default: default:
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:type should be BOOLEAN"))); absl::StrCat("field:", field_name, " error:type should be BOOLEAN")));
return false; return false;
} }
@ -56,7 +56,7 @@ bool ExtractJsonArray(const Json& json, absl::string_view field_name,
std::vector<grpc_error_handle>* error_list) { std::vector<grpc_error_handle>* error_list) {
if (json.type() != Json::Type::ARRAY) { if (json.type() != Json::Type::ARRAY) {
*output = nullptr; *output = nullptr;
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:type should be ARRAY"))); absl::StrCat("field:", field_name, " error:type should be ARRAY")));
return false; return false;
} }
@ -69,7 +69,7 @@ bool ExtractJsonObject(const Json& json, absl::string_view field_name,
std::vector<grpc_error_handle>* error_list) { std::vector<grpc_error_handle>* error_list) {
if (json.type() != Json::Type::OBJECT) { if (json.type() != Json::Type::OBJECT) {
*output = nullptr; *output = nullptr;
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:type should be OBJECT"))); absl::StrCat("field:", field_name, " error:type should be OBJECT")));
return false; return false;
} }
@ -87,14 +87,14 @@ bool ParseJsonObjectFieldAsDuration(const Json::Object& object,
auto it = object.find(std::string(field_name)); auto it = object.find(std::string(field_name));
if (it == object.end()) { if (it == object.end()) {
if (required) { if (required) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:does not exist."))); absl::StrCat("field:", field_name, " error:does not exist.")));
} }
return false; return false;
} }
if (!ParseDurationFromJson(it->second, output)) { if (!ParseDurationFromJson(it->second, output)) {
*output = Duration::NegativeInfinity(); *output = Duration::NegativeInfinity();
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, absl::StrCat("field:", field_name,
" error:type should be STRING of the form given by " " error:type should be STRING of the form given by "
"google.proto.Duration."))); "google.proto.Duration.")));

@ -55,12 +55,12 @@ bool ExtractJsonNumber(const Json& json, absl::string_view field_name,
std::vector<grpc_error_handle>* error_list) { std::vector<grpc_error_handle>* error_list) {
static_assert(std::is_integral<NumericType>::value, "Integral required"); static_assert(std::is_integral<NumericType>::value, "Integral required");
if (json.type() != Json::Type::NUMBER && json.type() != Json::Type::STRING) { if (json.type() != Json::Type::NUMBER && json.type() != Json::Type::STRING) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( error_list->push_back(GRPC_ERROR_CREATE(absl::StrCat(
"field:", field_name, " error:type should be NUMBER or STRING"))); "field:", field_name, " error:type should be NUMBER or STRING")));
return false; return false;
} }
if (!absl::SimpleAtoi(json.string_value(), output)) { if (!absl::SimpleAtoi(json.string_value(), output)) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:failed to parse."))); absl::StrCat("field:", field_name, " error:failed to parse.")));
return false; return false;
} }
@ -77,7 +77,7 @@ bool ExtractJsonString(const Json& json, absl::string_view field_name,
std::vector<grpc_error_handle>* error_list) { std::vector<grpc_error_handle>* error_list) {
if (json.type() != Json::Type::STRING) { if (json.type() != Json::Type::STRING) {
*output = ""; *output = "";
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:type should be STRING"))); absl::StrCat("field:", field_name, " error:type should be STRING")));
return false; return false;
} }
@ -142,7 +142,7 @@ bool ParseJsonObjectField(const Json::Object& object,
auto it = object.find(std::string(field_name)); auto it = object.find(std::string(field_name));
if (it == object.end()) { if (it == object.end()) {
if (required) { if (required) {
error_list->push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list->push_back(GRPC_ERROR_CREATE(
absl::StrCat("field:", field_name, " error:does not exist."))); absl::StrCat("field:", field_name, " error:does not exist.")));
} }
return false; return false;

@ -94,29 +94,24 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials(
audience_ = options.audience; audience_ = options.audience;
auto it = options.credential_source.object_value().find("environment_id"); auto it = options.credential_source.object_value().find("environment_id");
if (it == options.credential_source.object_value().end()) { if (it == options.credential_source.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("environment_id field not present.");
"environment_id field not present.");
return; return;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("environment_id field must be a string.");
"environment_id field must be a string.");
return; return;
} }
if (it->second.string_value() != kExpectedEnvironmentId) { if (it->second.string_value() != kExpectedEnvironmentId) {
*error = *error = GRPC_ERROR_CREATE("environment_id does not match.");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("environment_id does not match.");
return; return;
} }
it = options.credential_source.object_value().find("region_url"); it = options.credential_source.object_value().find("region_url");
if (it == options.credential_source.object_value().end()) { if (it == options.credential_source.object_value().end()) {
*error = *error = GRPC_ERROR_CREATE("region_url field not present.");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("region_url field not present.");
return; return;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("region_url field must be a string.");
"region_url field must be a string.");
return; return;
} }
region_url_ = it->second.string_value(); region_url_ = it->second.string_value();
@ -128,12 +123,12 @@ AwsExternalAccountCredentials::AwsExternalAccountCredentials(
it = options.credential_source.object_value().find( it = options.credential_source.object_value().find(
"regional_cred_verification_url"); "regional_cred_verification_url");
if (it == options.credential_source.object_value().end()) { if (it == options.credential_source.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error =
"regional_cred_verification_url field not present."); GRPC_ERROR_CREATE("regional_cred_verification_url field not present.");
return; return;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"regional_cred_verification_url field must be a string."); "regional_cred_verification_url field must be a string.");
return; return;
} }
@ -152,7 +147,7 @@ void AwsExternalAccountCredentials::RetrieveSubjectToken(
if (ctx == nullptr) { if (ctx == nullptr) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", "",
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE(
"Missing HTTPRequestContext to start subject token retrieval.")); "Missing HTTPRequestContext to start subject token retrieval."));
return; return;
} }
@ -252,8 +247,8 @@ void AwsExternalAccountCredentials::RetrieveRegion() {
absl::StatusOr<URI> uri = URI::Parse(region_url_); absl::StatusOr<URI> uri = URI::Parse(region_url_);
if (!uri.ok()) { if (!uri.ok()) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( "", GRPC_ERROR_CREATE(absl::StrFormat("Invalid region url. %s",
"Invalid region url. %s", uri.status().ToString()))); uri.status().ToString())));
return; return;
} }
grpc_http_request request; grpc_http_request request;
@ -305,7 +300,7 @@ void AwsExternalAccountCredentials::RetrieveRoleName() {
absl::StatusOr<URI> uri = URI::Parse(url_); absl::StatusOr<URI> uri = URI::Parse(url_);
if (!uri.ok()) { if (!uri.ok()) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_CPP_STRING( "", GRPC_ERROR_CREATE(
absl::StrFormat("Invalid url: %s.", uri.status().ToString()))); absl::StrFormat("Invalid url: %s.", uri.status().ToString())));
return; return;
} }
@ -362,16 +357,16 @@ void AwsExternalAccountCredentials::RetrieveSigningKeys() {
} }
if (role_name_.empty()) { if (role_name_.empty()) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_STATIC_STRING( "",
"Missing role name when retrieving signing keys.")); GRPC_ERROR_CREATE("Missing role name when retrieving signing keys."));
return; return;
} }
std::string url_with_role_name = absl::StrCat(url_, "/", role_name_); std::string url_with_role_name = absl::StrCat(url_, "/", role_name_);
absl::StatusOr<URI> uri = URI::Parse(url_with_role_name); absl::StatusOr<URI> uri = URI::Parse(url_with_role_name);
if (!uri.ok()) { if (!uri.ok()) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( "", GRPC_ERROR_CREATE(absl::StrFormat("Invalid url with role name: %s.",
"Invalid url with role name: %s.", uri.status().ToString()))); uri.status().ToString())));
return; return;
} }
grpc_http_request request; grpc_http_request request;
@ -414,16 +409,15 @@ void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal(
auto json = Json::Parse(response_body); auto json = Json::Parse(response_body);
if (!json.ok()) { if (!json.ok()) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_CPP_STRING( "", GRPC_ERROR_CREATE(
absl::StrCat("Invalid retrieve signing keys response: ", absl::StrCat("Invalid retrieve signing keys response: ",
json.status().ToString()))); json.status().ToString())));
return; return;
} }
if (json->type() != Json::Type::OBJECT) { if (json->type() != Json::Type::OBJECT) {
FinishRetrieveSubjectToken("", FinishRetrieveSubjectToken(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( "", GRPC_ERROR_CREATE("Invalid retrieve signing keys response: "
"Invalid retrieve signing keys response: " "JSON type is not object"));
"JSON type is not object"));
return; return;
} }
auto it = json->object_value().find("AccessKeyId"); auto it = json->object_value().find("AccessKeyId");
@ -432,7 +426,7 @@ void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal(
access_key_id_ = it->second.string_value(); access_key_id_ = it->second.string_value();
} else { } else {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( "", GRPC_ERROR_CREATE(absl::StrFormat(
"Missing or invalid AccessKeyId in %s.", response_body))); "Missing or invalid AccessKeyId in %s.", response_body)));
return; return;
} }
@ -442,7 +436,7 @@ void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal(
secret_access_key_ = it->second.string_value(); secret_access_key_ = it->second.string_value();
} else { } else {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( "", GRPC_ERROR_CREATE(absl::StrFormat(
"Missing or invalid SecretAccessKey in %s.", response_body))); "Missing or invalid SecretAccessKey in %s.", response_body)));
return; return;
} }
@ -452,8 +446,8 @@ void AwsExternalAccountCredentials::OnRetrieveSigningKeysInternal(
token_ = it->second.string_value(); token_ = it->second.string_value();
} else { } else {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( "", GRPC_ERROR_CREATE(absl::StrFormat("Missing or invalid Token in %s.",
"Missing or invalid Token in %s.", response_body))); response_body)));
return; return;
} }
BuildSubjectToken(); BuildSubjectToken();
@ -470,18 +464,17 @@ void AwsExternalAccountCredentials::BuildSubjectToken() {
std::map<std::string, std::string>(), &error); std::map<std::string, std::string>(), &error);
if (!error.ok()) { if (!error.ok()) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "", GRPC_ERROR_CREATE_REFERENCING(
"Creating aws request signer failed.", &error, 1)); "Creating aws request signer failed.", &error, 1));
return; return;
} }
} }
auto signed_headers = signer_->GetSignedRequestHeaders(); auto signed_headers = signer_->GetSignedRequestHeaders();
if (!error.ok()) { if (!error.ok()) {
FinishRetrieveSubjectToken("", FinishRetrieveSubjectToken(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "", GRPC_ERROR_CREATE_REFERENCING("Invalid getting signed request"
"Invalid getting signed request" "headers.",
"headers.", &error, 1));
&error, 1));
return; return;
} }
// Construct subject token // Construct subject token

@ -88,7 +88,7 @@ AwsRequestSigner::AwsRequestSigner(
auto date_it = additional_headers_.find("date"); auto date_it = additional_headers_.find("date");
if (amz_date_it != additional_headers_.end() && if (amz_date_it != additional_headers_.end() &&
date_it != additional_headers_.end()) { date_it != additional_headers_.end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"Only one of {date, x-amz-date} can be specified, not both."); "Only one of {date, x-amz-date} can be specified, not both.");
return; return;
} }
@ -99,7 +99,7 @@ AwsRequestSigner::AwsRequestSigner(
std::string err_str; std::string err_str;
if (!absl::ParseTime(kDateFormat, date_it->second, &request_date, if (!absl::ParseTime(kDateFormat, date_it->second, &request_date,
&err_str)) { &err_str)) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(err_str.c_str()); *error = GRPC_ERROR_CREATE(err_str.c_str());
return; return;
} }
static_request_date_ = static_request_date_ =
@ -107,7 +107,7 @@ AwsRequestSigner::AwsRequestSigner(
} }
absl::StatusOr<URI> tmp_url = URI::Parse(url); absl::StatusOr<URI> tmp_url = URI::Parse(url);
if (!tmp_url.ok()) { if (!tmp_url.ok()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid Aws request url."); *error = GRPC_ERROR_CREATE("Invalid Aws request url.");
return; return;
} }
url_ = tmp_url.value(); url_ = tmp_url.value();

@ -108,47 +108,41 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
Options options; Options options;
options.type = GRPC_AUTH_JSON_TYPE_INVALID; options.type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json.type() != Json::Type::OBJECT) { if (json.type() != Json::Type::OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error =
"Invalid json to construct credentials options."); GRPC_ERROR_CREATE("Invalid json to construct credentials options.");
return nullptr; return nullptr;
} }
auto it = json.object_value().find("type"); auto it = json.object_value().find("type");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("type field not present."); *error = GRPC_ERROR_CREATE("type field not present.");
return nullptr; return nullptr;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = *error = GRPC_ERROR_CREATE("type field must be a string.");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("type field must be a string.");
return nullptr; return nullptr;
} }
if (it->second.string_value() != GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT) { if (it->second.string_value() != GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT) {
*error = *error = GRPC_ERROR_CREATE("Invalid credentials json type.");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid credentials json type.");
return nullptr; return nullptr;
} }
options.type = GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT; options.type = GRPC_AUTH_JSON_TYPE_EXTERNAL_ACCOUNT;
it = json.object_value().find("audience"); it = json.object_value().find("audience");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
*error = *error = GRPC_ERROR_CREATE("audience field not present.");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("audience field not present.");
return nullptr; return nullptr;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("audience field must be a string.");
"audience field must be a string.");
return nullptr; return nullptr;
} }
options.audience = it->second.string_value(); options.audience = it->second.string_value();
it = json.object_value().find("subject_token_type"); it = json.object_value().find("subject_token_type");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("subject_token_type field not present.");
"subject_token_type field not present.");
return nullptr; return nullptr;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("subject_token_type field must be a string.");
"subject_token_type field must be a string.");
return nullptr; return nullptr;
} }
options.subject_token_type = it->second.string_value(); options.subject_token_type = it->second.string_value();
@ -158,13 +152,11 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
} }
it = json.object_value().find("token_url"); it = json.object_value().find("token_url");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
*error = *error = GRPC_ERROR_CREATE("token_url field not present.");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("token_url field not present.");
return nullptr; return nullptr;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("token_url field must be a string.");
"token_url field must be a string.");
return nullptr; return nullptr;
} }
options.token_url = it->second.string_value(); options.token_url = it->second.string_value();
@ -174,8 +166,7 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
} }
it = json.object_value().find("credential_source"); it = json.object_value().find("credential_source");
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("credential_source field not present.");
"credential_source field not present.");
return nullptr; return nullptr;
} }
options.credential_source = it->second; options.credential_source = it->second;
@ -196,7 +187,7 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
if (MatchWorkforcePoolAudience(options.audience)) { if (MatchWorkforcePoolAudience(options.audience)) {
options.workforce_pool_user_project = it->second.string_value(); options.workforce_pool_user_project = it->second.string_value();
} else { } else {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"workforce_pool_user_project should not be set for non-workforce " "workforce_pool_user_project should not be set for non-workforce "
"pool credentials"); "pool credentials");
return nullptr; return nullptr;
@ -216,7 +207,7 @@ RefCountedPtr<ExternalAccountCredentials> ExternalAccountCredentials::Create(
creds = MakeRefCounted<UrlExternalAccountCredentials>( creds = MakeRefCounted<UrlExternalAccountCredentials>(
std::move(options), std::move(scopes), error); std::move(options), std::move(scopes), error);
} else { } else {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"Invalid options credential source to create " "Invalid options credential source to create "
"ExternalAccountCredentials."); "ExternalAccountCredentials.");
} }
@ -283,7 +274,7 @@ void ExternalAccountCredentials::ExchangeToken(
absl::string_view subject_token) { absl::string_view subject_token) {
absl::StatusOr<URI> uri = URI::Parse(options_.token_url); absl::StatusOr<URI> uri = URI::Parse(options_.token_url);
if (!uri.ok()) { if (!uri.ok()) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_CPP_STRING( FinishTokenFetch(GRPC_ERROR_CREATE(
absl::StrFormat("Invalid token url: %s. Error: %s", options_.token_url, absl::StrFormat("Invalid token url: %s. Error: %s", options_.token_url,
uri.status().ToString()))); uri.status().ToString())));
return; return;
@ -399,19 +390,19 @@ void ExternalAccountCredentials::ImpersenateServiceAccount() {
ctx_->response.body_length); ctx_->response.body_length);
auto json = Json::Parse(response_body); auto json = Json::Parse(response_body);
if (!json.ok()) { if (!json.ok()) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrCat(
"Invalid token exchange response: ", json.status().ToString()))); "Invalid token exchange response: ", json.status().ToString())));
return; return;
} }
if (json->type() != Json::Type::OBJECT) { if (json->type() != Json::Type::OBJECT) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_STATIC_STRING( FinishTokenFetch(GRPC_ERROR_CREATE(
"Invalid token exchange response: JSON type is not object")); "Invalid token exchange response: JSON type is not object"));
return; return;
} }
auto it = json->object_value().find("access_token"); auto it = json->object_value().find("access_token");
if (it == json->object_value().end() || if (it == json->object_value().end() ||
it->second.type() != Json::Type::STRING) { it->second.type() != Json::Type::STRING) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat(
"Missing or invalid access_token in %s.", response_body))); "Missing or invalid access_token in %s.", response_body)));
return; return;
} }
@ -419,7 +410,7 @@ void ExternalAccountCredentials::ImpersenateServiceAccount() {
absl::StatusOr<URI> uri = absl::StatusOr<URI> uri =
URI::Parse(options_.service_account_impersonation_url); URI::Parse(options_.service_account_impersonation_url);
if (!uri.ok()) { if (!uri.ok()) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat(
"Invalid service account impersonation url: %s. Error: %s", "Invalid service account impersonation url: %s. Error: %s",
options_.service_account_impersonation_url, uri.status().ToString()))); options_.service_account_impersonation_url, uri.status().ToString())));
return; return;
@ -477,21 +468,21 @@ void ExternalAccountCredentials::OnImpersenateServiceAccountInternal(
ctx_->response.body_length); ctx_->response.body_length);
auto json = Json::Parse(response_body); auto json = Json::Parse(response_body);
if (!json.ok()) { if (!json.ok()) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_CPP_STRING( FinishTokenFetch(GRPC_ERROR_CREATE(
absl::StrCat("Invalid service account impersonation response: ", absl::StrCat("Invalid service account impersonation response: ",
json.status().ToString()))); json.status().ToString())));
return; return;
} }
if (json->type() != Json::Type::OBJECT) { if (json->type() != Json::Type::OBJECT) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_STATIC_STRING( FinishTokenFetch(
"Invalid service account impersonation response: " GRPC_ERROR_CREATE("Invalid service account impersonation response: "
"JSON type is not object")); "JSON type is not object"));
return; return;
} }
auto it = json->object_value().find("accessToken"); auto it = json->object_value().find("accessToken");
if (it == json->object_value().end() || if (it == json->object_value().end() ||
it->second.type() != Json::Type::STRING) { it->second.type() != Json::Type::STRING) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat(
"Missing or invalid accessToken in %s.", response_body))); "Missing or invalid accessToken in %s.", response_body)));
return; return;
} }
@ -499,14 +490,14 @@ void ExternalAccountCredentials::OnImpersenateServiceAccountInternal(
it = json->object_value().find("expireTime"); it = json->object_value().find("expireTime");
if (it == json->object_value().end() || if (it == json->object_value().end() ||
it->second.type() != Json::Type::STRING) { it->second.type() != Json::Type::STRING) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( FinishTokenFetch(GRPC_ERROR_CREATE(absl::StrFormat(
"Missing or invalid expireTime in %s.", response_body))); "Missing or invalid expireTime in %s.", response_body)));
return; return;
} }
std::string expire_time = it->second.string_value(); std::string expire_time = it->second.string_value();
absl::Time t; absl::Time t;
if (!absl::ParseTime(absl::RFC3339_full, expire_time, &t, nullptr)) { if (!absl::ParseTime(absl::RFC3339_full, expire_time, &t, nullptr)) {
FinishTokenFetch(GRPC_ERROR_CREATE_FROM_STATIC_STRING( FinishTokenFetch(GRPC_ERROR_CREATE(
"Invalid expire time of service account impersonation response.")); "Invalid expire time of service account impersonation response."));
return; return;
} }

@ -51,12 +51,11 @@ FileExternalAccountCredentials::FileExternalAccountCredentials(
: ExternalAccountCredentials(options, std::move(scopes)) { : ExternalAccountCredentials(options, std::move(scopes)) {
auto it = options.credential_source.object_value().find("file"); auto it = options.credential_source.object_value().find("file");
if (it == options.credential_source.object_value().end()) { if (it == options.credential_source.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("file field not present."); *error = GRPC_ERROR_CREATE("file field not present.");
return; return;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = *error = GRPC_ERROR_CREATE("file field must be a string.");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("file field must be a string.");
return; return;
} }
file_ = it->second.string_value(); file_ = it->second.string_value();
@ -64,32 +63,30 @@ FileExternalAccountCredentials::FileExternalAccountCredentials(
if (it != options.credential_source.object_value().end()) { if (it != options.credential_source.object_value().end()) {
const Json& format_json = it->second; const Json& format_json = it->second;
if (format_json.type() != Json::Type::OBJECT) { if (format_json.type() != Json::Type::OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"The JSON value of credential source format is not an object."); "The JSON value of credential source format is not an object.");
return; return;
} }
auto format_it = format_json.object_value().find("type"); auto format_it = format_json.object_value().find("type");
if (format_it == format_json.object_value().end()) { if (format_it == format_json.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("format.type field not present.");
"format.type field not present.");
return; return;
} }
if (format_it->second.type() != Json::Type::STRING) { if (format_it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("format.type field must be a string.");
"format.type field must be a string.");
return; return;
} }
format_type_ = format_it->second.string_value(); format_type_ = format_it->second.string_value();
if (format_type_ == "json") { if (format_type_ == "json") {
format_it = format_json.object_value().find("subject_token_field_name"); format_it = format_json.object_value().find("subject_token_field_name");
if (format_it == format_json.object_value().end()) { if (format_it == format_json.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"format.subject_token_field_name field must be present if the " "format.subject_token_field_name field must be present if the "
"format is in Json."); "format is in Json.");
return; return;
} }
if (format_it->second.type() != Json::Type::STRING) { if (format_it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"format.subject_token_field_name field must be a string."); "format.subject_token_field_name field must be a string.");
return; return;
} }
@ -118,20 +115,18 @@ void FileExternalAccountCredentials::RetrieveSubjectToken(
if (format_type_ == "json") { if (format_type_ == "json") {
auto content_json = Json::Parse(content); auto content_json = Json::Parse(content);
if (!content_json.ok() || content_json->type() != Json::Type::OBJECT) { if (!content_json.ok() || content_json->type() != Json::Type::OBJECT) {
cb("", GRPC_ERROR_CREATE_FROM_STATIC_STRING( cb("", GRPC_ERROR_CREATE(
"The content of the file is not a valid json object.")); "The content of the file is not a valid json object."));
return; return;
} }
auto content_it = auto content_it =
content_json->object_value().find(format_subject_token_field_name_); content_json->object_value().find(format_subject_token_field_name_);
if (content_it == content_json->object_value().end()) { if (content_it == content_json->object_value().end()) {
cb("", GRPC_ERROR_CREATE_FROM_STATIC_STRING( cb("", GRPC_ERROR_CREATE("Subject token field not present."));
"Subject token field not present."));
return; return;
} }
if (content_it->second.type() != Json::Type::STRING) { if (content_it->second.type() != Json::Type::STRING) {
cb("", GRPC_ERROR_CREATE_FROM_STATIC_STRING( cb("", GRPC_ERROR_CREATE("Subject token field must be a string."));
"Subject token field must be a string."));
return; return;
} }
cb(content_it->second.string_value(), absl::OkStatus()); cb(content_it->second.string_value(), absl::OkStatus());

@ -62,17 +62,16 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
: ExternalAccountCredentials(options, std::move(scopes)) { : ExternalAccountCredentials(options, std::move(scopes)) {
auto it = options.credential_source.object_value().find("url"); auto it = options.credential_source.object_value().find("url");
if (it == options.credential_source.object_value().end()) { if (it == options.credential_source.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("url field not present."); *error = GRPC_ERROR_CREATE("url field not present.");
return; return;
} }
if (it->second.type() != Json::Type::STRING) { if (it->second.type() != Json::Type::STRING) {
*error = *error = GRPC_ERROR_CREATE("url field must be a string.");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("url field must be a string.");
return; return;
} }
absl::StatusOr<URI> tmp_url = URI::Parse(it->second.string_value()); absl::StatusOr<URI> tmp_url = URI::Parse(it->second.string_value());
if (!tmp_url.ok()) { if (!tmp_url.ok()) {
*error = GRPC_ERROR_CREATE_FROM_CPP_STRING( *error = GRPC_ERROR_CREATE(
absl::StrFormat("Invalid credential source url. Error: %s", absl::StrFormat("Invalid credential source url. Error: %s",
tmp_url.status().ToString())); tmp_url.status().ToString()));
return; return;
@ -85,7 +84,7 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
it = options.credential_source.object_value().find("headers"); it = options.credential_source.object_value().find("headers");
if (it != options.credential_source.object_value().end()) { if (it != options.credential_source.object_value().end()) {
if (it->second.type() != Json::Type::OBJECT) { if (it->second.type() != Json::Type::OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"The JSON value of credential source headers is not an object."); "The JSON value of credential source headers is not an object.");
return; return;
} }
@ -97,32 +96,30 @@ UrlExternalAccountCredentials::UrlExternalAccountCredentials(
if (it != options.credential_source.object_value().end()) { if (it != options.credential_source.object_value().end()) {
const Json& format_json = it->second; const Json& format_json = it->second;
if (format_json.type() != Json::Type::OBJECT) { if (format_json.type() != Json::Type::OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"The JSON value of credential source format is not an object."); "The JSON value of credential source format is not an object.");
return; return;
} }
auto format_it = format_json.object_value().find("type"); auto format_it = format_json.object_value().find("type");
if (format_it == format_json.object_value().end()) { if (format_it == format_json.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("format.type field not present.");
"format.type field not present.");
return; return;
} }
if (format_it->second.type() != Json::Type::STRING) { if (format_it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE("format.type field must be a string.");
"format.type field must be a string.");
return; return;
} }
format_type_ = format_it->second.string_value(); format_type_ = format_it->second.string_value();
if (format_type_ == "json") { if (format_type_ == "json") {
format_it = format_json.object_value().find("subject_token_field_name"); format_it = format_json.object_value().find("subject_token_field_name");
if (format_it == format_json.object_value().end()) { if (format_it == format_json.object_value().end()) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"format.subject_token_field_name field must be present if the " "format.subject_token_field_name field must be present if the "
"format is in Json."); "format is in Json.");
return; return;
} }
if (format_it->second.type() != Json::Type::STRING) { if (format_it->second.type() != Json::Type::STRING) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(
"format.subject_token_field_name field must be a string."); "format.subject_token_field_name field must be a string.");
return; return;
} }
@ -137,7 +134,7 @@ void UrlExternalAccountCredentials::RetrieveSubjectToken(
if (ctx == nullptr) { if (ctx == nullptr) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", "",
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE(
"Missing HTTPRequestContext to start subject token retrieval.")); "Missing HTTPRequestContext to start subject token retrieval."));
return; return;
} }
@ -205,21 +202,20 @@ void UrlExternalAccountCredentials::OnRetrieveSubjectTokenInternal(
auto response_json = Json::Parse(response_body); auto response_json = Json::Parse(response_body);
if (!response_json.ok() || response_json->type() != Json::Type::OBJECT) { if (!response_json.ok() || response_json->type() != Json::Type::OBJECT) {
FinishRetrieveSubjectToken( FinishRetrieveSubjectToken(
"", GRPC_ERROR_CREATE_FROM_STATIC_STRING( "", GRPC_ERROR_CREATE(
"The format of response is not a valid json object.")); "The format of response is not a valid json object."));
return; return;
} }
auto response_it = auto response_it =
response_json->object_value().find(format_subject_token_field_name_); response_json->object_value().find(format_subject_token_field_name_);
if (response_it == response_json->object_value().end()) { if (response_it == response_json->object_value().end()) {
FinishRetrieveSubjectToken("", GRPC_ERROR_CREATE_FROM_STATIC_STRING( FinishRetrieveSubjectToken(
"Subject token field not present.")); "", GRPC_ERROR_CREATE("Subject token field not present."));
return; return;
} }
if (response_it->second.type() != Json::Type::STRING) { if (response_it->second.type() != Json::Type::STRING) {
FinishRetrieveSubjectToken("", FinishRetrieveSubjectToken(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( "", GRPC_ERROR_CREATE("Subject token field must be a string."));
"Subject token field must be a string."));
return; return;
} }
FinishRetrieveSubjectToken(response_it->second.string_value(), error); FinishRetrieveSubjectToken(response_it->second.string_value(), error);

@ -311,7 +311,7 @@ static grpc_error_handle create_default_creds_from_path(
grpc_error_handle error; grpc_error_handle error;
Json json; Json json;
if (creds_path.empty()) { if (creds_path.empty()) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("creds_path unset"); error = GRPC_ERROR_CREATE("creds_path unset");
goto end; goto end;
} }
error = grpc_load_file(creds_path.c_str(), 0, &creds_data); error = grpc_load_file(creds_path.c_str(), 0, &creds_data);
@ -325,10 +325,9 @@ static grpc_error_handle create_default_creds_from_path(
json = std::move(*json_or); json = std::move(*json_or);
} }
if (json.type() != Json::Type::OBJECT) { if (json.type() != Json::Type::OBJECT) {
error = grpc_error_set_str( error = grpc_error_set_str(GRPC_ERROR_CREATE("Failed to parse JSON"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to parse JSON"), grpc_core::StatusStrProperty::kRawBytes,
grpc_core::StatusStrProperty::kRawBytes, grpc_core::StringViewFromSlice(creds_data));
grpc_core::StringViewFromSlice(creds_data));
goto end; goto end;
} }
@ -339,7 +338,7 @@ static grpc_error_handle create_default_creds_from_path(
grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
key, grpc_max_auth_token_lifetime()); key, grpc_max_auth_token_lifetime());
if (result == nullptr) { if (result == nullptr) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE(
"grpc_service_account_jwt_access_credentials_create_from_auth_json_" "grpc_service_account_jwt_access_credentials_create_from_auth_json_"
"key failed"); "key failed");
} }
@ -352,7 +351,7 @@ static grpc_error_handle create_default_creds_from_path(
result = result =
grpc_refresh_token_credentials_create_from_auth_refresh_token(token); grpc_refresh_token_credentials_create_from_auth_refresh_token(token);
if (result == nullptr) { if (result == nullptr) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE(
"grpc_refresh_token_credentials_create_from_auth_refresh_token " "grpc_refresh_token_credentials_create_from_auth_refresh_token "
"failed"); "failed");
} }
@ -361,8 +360,7 @@ static grpc_error_handle create_default_creds_from_path(
/* Finally try an external account credentials.*/ /* Finally try an external account credentials.*/
if (!ValidateExteralAccountCredentials(json)) { if (!ValidateExteralAccountCredentials(json)) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE("Invalid external account credentials format.");
"Invalid external account credentials format.");
goto end; goto end;
} }
result = grpc_core::ExternalAccountCredentials::Create(json, {}, &error); result = grpc_core::ExternalAccountCredentials::Create(json, {}, &error);
@ -420,11 +418,9 @@ static grpc_core::RefCountedPtr<grpc_call_credentials> make_default_call_creds(
call_creds = grpc_core::RefCountedPtr<grpc_call_credentials>( call_creds = grpc_core::RefCountedPtr<grpc_call_credentials>(
grpc_google_compute_engine_credentials_create(nullptr)); grpc_google_compute_engine_credentials_create(nullptr));
if (call_creds == nullptr) { if (call_creds == nullptr) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error = GRPC_ERROR_CREATE(GRPC_GOOGLE_CREDENTIAL_CREATION_ERROR);
GRPC_GOOGLE_CREDENTIAL_CREATION_ERROR);
*error = grpc_error_add_child( *error = grpc_error_add_child(
*error, GRPC_ERROR_CREATE_FROM_STATIC_STRING( *error, GRPC_ERROR_CREATE("Failed to get credentials from network"));
"Failed to get credentials from network"));
} }
} }

@ -273,7 +273,7 @@ void grpc_oauth2_token_fetcher_credentials::on_http_response(
[](absl::string_view, const grpc_core::Slice&) { abort(); }); [](absl::string_view, const grpc_core::Slice&) { abort(); });
pending_request->result = std::move(pending_request->md); pending_request->result = std::move(pending_request->md);
} else { } else {
auto err = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( auto err = GRPC_ERROR_CREATE_REFERENCING(
"Error occurred when fetching oauth2 token.", &error, 1); "Error occurred when fetching oauth2 token.", &error, 1);
pending_request->result = grpc_error_to_absl_status(err); pending_request->result = grpc_error_to_absl_status(err);
} }
@ -534,7 +534,7 @@ grpc_error_handle LoadTokenFile(const char* path, gpr_slice* token) {
if (!err.ok()) return err; if (!err.ok()) return err;
if (GRPC_SLICE_LENGTH(*token) == 0) { if (GRPC_SLICE_LENGTH(*token) == 0) {
gpr_log(GPR_ERROR, "Token file %s is empty", path); gpr_log(GPR_ERROR, "Token file %s is empty", path);
err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Token file is empty."); err = GRPC_ERROR_CREATE("Token file is empty.");
} }
return err; return err;
} }
@ -662,22 +662,22 @@ absl::StatusOr<URI> ValidateStsCredentialsOptions(
? "" ? ""
: options->token_exchange_service_uri); : options->token_exchange_service_uri);
if (!sts_url.ok()) { if (!sts_url.ok()) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( error_list.push_back(GRPC_ERROR_CREATE(
absl::StrFormat("Invalid or missing STS endpoint URL. Error: %s", absl::StrFormat("Invalid or missing STS endpoint URL. Error: %s",
sts_url.status().ToString()))); sts_url.status().ToString())));
} else if (sts_url->scheme() != "https" && sts_url->scheme() != "http") { } else if (sts_url->scheme() != "https" && sts_url->scheme() != "http") {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"Invalid URI scheme, must be https to http.")); GRPC_ERROR_CREATE("Invalid URI scheme, must be https to http."));
} }
if (options->subject_token_path == nullptr || if (options->subject_token_path == nullptr ||
strlen(options->subject_token_path) == 0) { strlen(options->subject_token_path) == 0) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"subject_token needs to be specified")); GRPC_ERROR_CREATE("subject_token needs to be specified"));
} }
if (options->subject_token_type == nullptr || if (options->subject_token_type == nullptr ||
strlen(options->subject_token_type) == 0) { strlen(options->subject_token_type) == 0) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( error_list.push_back(
"subject_token_type needs to be specified")); GRPC_ERROR_CREATE("subject_token_type needs to be specified"));
} }
if (error_list.empty()) { if (error_list.empty()) {
return sts_url; return sts_url;

@ -83,12 +83,12 @@ StaticDataCertificateProvider::StaticDataCertificateProvider(
grpc_error_handle root_cert_error; grpc_error_handle root_cert_error;
grpc_error_handle identity_cert_error; grpc_error_handle identity_cert_error;
if (root_being_watched && !root_has_update) { if (root_being_watched && !root_has_update) {
root_cert_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( root_cert_error =
"Unable to get latest root certificates."); GRPC_ERROR_CREATE("Unable to get latest root certificates.");
} }
if (identity_being_watched && !identity_has_update) { if (identity_being_watched && !identity_has_update) {
identity_cert_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( identity_cert_error =
"Unable to get latest identity certificates."); GRPC_ERROR_CREATE("Unable to get latest identity certificates.");
} }
if (!root_cert_error.ok() || !identity_cert_error.ok()) { if (!root_cert_error.ok() || !identity_cert_error.ok()) {
distributor_->SetErrorForCert(cert_name, root_cert_error, distributor_->SetErrorForCert(cert_name, root_cert_error,
@ -177,12 +177,12 @@ FileWatcherCertificateProvider::FileWatcherCertificateProvider(
grpc_error_handle root_cert_error; grpc_error_handle root_cert_error;
grpc_error_handle identity_cert_error; grpc_error_handle identity_cert_error;
if (root_being_watched && !root_certificate.has_value()) { if (root_being_watched && !root_certificate.has_value()) {
root_cert_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( root_cert_error =
"Unable to get latest root certificates."); GRPC_ERROR_CREATE("Unable to get latest root certificates.");
} }
if (identity_being_watched && !pem_key_cert_pairs.has_value()) { if (identity_being_watched && !pem_key_cert_pairs.has_value()) {
identity_cert_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( identity_cert_error =
"Unable to get latest identity certificates."); GRPC_ERROR_CREATE("Unable to get latest identity certificates.");
} }
if (!root_cert_error.ok() || !identity_cert_error.ok()) { if (!root_cert_error.ok() || !identity_cert_error.ok()) {
distributor_->SetErrorForCert(cert_name, root_cert_error, distributor_->SetErrorForCert(cert_name, root_cert_error,
@ -238,11 +238,10 @@ void FileWatcherCertificateProvider::ForceUpdate() {
} }
if (root_cert_changed || identity_cert_changed) { if (root_cert_changed || identity_cert_changed) {
ExecCtx exec_ctx; ExecCtx exec_ctx;
grpc_error_handle root_cert_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( grpc_error_handle root_cert_error =
"Unable to get latest root certificates."); GRPC_ERROR_CREATE("Unable to get latest root certificates.");
grpc_error_handle identity_cert_error = grpc_error_handle identity_cert_error =
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("Unable to get latest identity certificates.");
"Unable to get latest identity certificates.");
for (const auto& p : watcher_info_) { for (const auto& p : watcher_info_) {
const std::string& cert_name = p.first; const std::string& cert_name = p.first;
const WatcherInfo& info = p.second; const WatcherInfo& info = p.second;

@ -78,8 +78,7 @@ void alts_check_peer(tsi_peer peer,
grpc_error_handle error = grpc_error_handle error =
*auth_context != nullptr *auth_context != nullptr
? absl::OkStatus() ? absl::OkStatus()
: GRPC_ERROR_CREATE_FROM_STATIC_STRING( : GRPC_ERROR_CREATE("Could not get ALTS auth context from TSI peer");
"Could not get ALTS auth context from TSI peer");
grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, error); grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, error);
} }

@ -213,36 +213,33 @@ void fake_check_peer(grpc_security_connector* /*sc*/, tsi_peer peer,
grpc_error_handle error; grpc_error_handle error;
*auth_context = nullptr; *auth_context = nullptr;
if (peer.property_count != 2) { if (peer.property_count != 2) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE("Fake peers should only have 2 properties.");
"Fake peers should only have 2 properties.");
goto end; goto end;
} }
prop_name = peer.properties[0].name; prop_name = peer.properties[0].name;
if (prop_name == nullptr || if (prop_name == nullptr ||
strcmp(prop_name, TSI_CERTIFICATE_TYPE_PEER_PROPERTY) != 0) { strcmp(prop_name, TSI_CERTIFICATE_TYPE_PEER_PROPERTY) != 0) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING( error = GRPC_ERROR_CREATE(
absl::StrCat("Unexpected property in fake peer: ", absl::StrCat("Unexpected property in fake peer: ",
prop_name == nullptr ? "<EMPTY>" : prop_name)); prop_name == nullptr ? "<EMPTY>" : prop_name));
goto end; goto end;
} }
if (strncmp(peer.properties[0].value.data, TSI_FAKE_CERTIFICATE_TYPE, if (strncmp(peer.properties[0].value.data, TSI_FAKE_CERTIFICATE_TYPE,
peer.properties[0].value.length) != 0) { peer.properties[0].value.length) != 0) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE("Invalid value for cert type property.");
"Invalid value for cert type property.");
goto end; goto end;
} }
prop_name = peer.properties[1].name; prop_name = peer.properties[1].name;
if (prop_name == nullptr || if (prop_name == nullptr ||
strcmp(prop_name, TSI_SECURITY_LEVEL_PEER_PROPERTY) != 0) { strcmp(prop_name, TSI_SECURITY_LEVEL_PEER_PROPERTY) != 0) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING( error = GRPC_ERROR_CREATE(
absl::StrCat("Unexpected property in fake peer: ", absl::StrCat("Unexpected property in fake peer: ",
prop_name == nullptr ? "<EMPTY>" : prop_name)); prop_name == nullptr ? "<EMPTY>" : prop_name));
goto end; goto end;
} }
if (strncmp(peer.properties[1].value.data, TSI_FAKE_SECURITY_LEVEL, if (strncmp(peer.properties[1].value.data, TSI_FAKE_SECURITY_LEVEL,
peer.properties[1].value.length) != 0) { peer.properties[1].value.length) != 0) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE("Invalid value for security level property.");
"Invalid value for security level property.");
goto end; goto end;
} }

@ -130,8 +130,8 @@ void local_check_peer(tsi_peer peer, grpc_endpoint* ep,
} }
grpc_error_handle error; grpc_error_handle error;
if (!is_endpoint_local) { if (!is_endpoint_local) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error =
"Endpoint is neither UDS or TCP loopback address."); GRPC_ERROR_CREATE("Endpoint is neither UDS or TCP loopback address.");
grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, error); grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, error);
return; return;
} }
@ -159,9 +159,9 @@ void local_check_peer(tsi_peer peer, grpc_endpoint* ep,
*/ */
*auth_context = local_auth_context_create(&peer); *auth_context = local_auth_context_create(&peer);
tsi_peer_destruct(&peer); tsi_peer_destruct(&peer);
error = *auth_context != nullptr ? absl::OkStatus() error = *auth_context != nullptr
: GRPC_ERROR_CREATE_FROM_STATIC_STRING( ? absl::OkStatus()
"Could not create local auth context"); : GRPC_ERROR_CREATE("Could not create local auth context");
grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, error); grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, error);
} }

@ -66,7 +66,7 @@ grpc_error_handle ssl_check_peer(
} }
/* Check the peer name if specified. */ /* Check the peer name if specified. */
if (peer_name != nullptr && !grpc_ssl_host_matches_name(peer, peer_name)) { if (peer_name != nullptr && !grpc_ssl_host_matches_name(peer, peer_name)) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrCat("Peer name ", peer_name, " is not in peer certificate")); absl::StrCat("Peer name ", peer_name, " is not in peer certificate"));
} }
*auth_context = *auth_context =
@ -163,8 +163,8 @@ class grpc_ssl_channel_security_connector final
const tsi_peer_property* p = const tsi_peer_property* p =
tsi_peer_get_property_by_name(&peer, TSI_X509_PEM_CERT_PROPERTY); tsi_peer_get_property_by_name(&peer, TSI_X509_PEM_CERT_PROPERTY);
if (p == nullptr) { if (p == nullptr) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( error =
"Cannot check peer: missing pem cert property."); GRPC_ERROR_CREATE("Cannot check peer: missing pem cert property.");
} else { } else {
char* peer_pem = static_cast<char*>(gpr_malloc(p->value.length + 1)); char* peer_pem = static_cast<char*>(gpr_malloc(p->value.length + 1));
memcpy(peer_pem, p->value.data, p->value.length); memcpy(peer_pem, p->value.data, p->value.length);
@ -174,7 +174,7 @@ class grpc_ssl_channel_security_connector final
verify_options_->verify_peer_callback_userdata); verify_options_->verify_peer_callback_userdata);
gpr_free(peer_pem); gpr_free(peer_pem);
if (callback_status) { if (callback_status) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat( error = GRPC_ERROR_CREATE(absl::StrFormat(
"Verify peer callback returned a failure (%d)", callback_status)); "Verify peer callback returned a failure (%d)", callback_status));
} }
} }

@ -144,12 +144,11 @@ grpc_error_handle grpc_ssl_check_alpn(const tsi_peer* peer) {
const tsi_peer_property* p = const tsi_peer_property* p =
tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL); tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL);
if (p == nullptr) { if (p == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE(
"Cannot check peer: missing selected ALPN property."); "Cannot check peer: missing selected ALPN property.");
} }
if (!grpc_chttp2_is_alpn_version_supported(p->value.data, p->value.length)) { if (!grpc_chttp2_is_alpn_version_supported(p->value.data, p->value.length)) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Cannot check peer: invalid ALPN value.");
"Cannot check peer: invalid ALPN value.");
} }
#endif /* TSI_OPENSSL_ALPN_SUPPORT */ #endif /* TSI_OPENSSL_ALPN_SUPPORT */
return absl::OkStatus(); return absl::OkStatus();
@ -159,7 +158,7 @@ grpc_error_handle grpc_ssl_check_peer_name(absl::string_view peer_name,
const tsi_peer* peer) { const tsi_peer* peer) {
/* Check the peer name if specified. */ /* Check the peer name if specified. */
if (!peer_name.empty() && !grpc_ssl_host_matches_name(peer, peer_name)) { if (!peer_name.empty() && !grpc_ssl_host_matches_name(peer, peer_name)) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING( return GRPC_ERROR_CREATE(
absl::StrCat("Peer name ", peer_name, " is not in peer certificate")); absl::StrCat("Peer name ", peer_name, " is not in peer certificate"));
} }
return absl::OkStatus(); return absl::OkStatus();

@ -503,7 +503,7 @@ void TlsChannelSecurityConnector::ChannelPendingVerifierRequest::OnVerifyDone(
} }
grpc_error_handle error; grpc_error_handle error;
if (!status.ok()) { if (!status.ok()) {
error = GRPC_ERROR_CREATE_FROM_COPIED_STRING( error = GRPC_ERROR_CREATE(
absl::StrCat("Custom verification check failed with error: ", absl::StrCat("Custom verification check failed with error: ",
status.ToString()) status.ToString())
.c_str()); .c_str());
@ -777,7 +777,7 @@ void TlsServerSecurityConnector::ServerPendingVerifierRequest::OnVerifyDone(
} }
grpc_error_handle error; grpc_error_handle error;
if (!status.ok()) { if (!status.ok()) {
error = GRPC_ERROR_CREATE_FROM_COPIED_STRING( error = GRPC_ERROR_CREATE(
absl::StrCat("Custom verification check failed with error: ", absl::StrCat("Custom verification check failed with error: ",
status.ToString()) status.ToString())
.c_str()); .c_str());

@ -263,8 +263,8 @@ static void on_read(void* user_data, grpc_error_handle error) {
if (!error.ok()) { if (!error.ok()) {
grpc_slice_buffer_reset_and_unref(ep->read_buffer); grpc_slice_buffer_reset_and_unref(ep->read_buffer);
call_read_cb(ep, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( call_read_cb(
"Secure read failed", &error, 1)); ep, GRPC_ERROR_CREATE_REFERENCING("Secure read failed", &error, 1));
return; return;
} }
@ -342,9 +342,8 @@ static void on_read(void* user_data, grpc_error_handle error) {
if (result != TSI_OK) { if (result != TSI_OK) {
grpc_slice_buffer_reset_and_unref(ep->read_buffer); grpc_slice_buffer_reset_and_unref(ep->read_buffer);
call_read_cb( call_read_cb(ep, grpc_set_tsi_error_result(
ep, grpc_set_tsi_error_result( GRPC_ERROR_CREATE("Unwrap failed"), result));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unwrap failed"), result));
return; return;
} }
@ -486,8 +485,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
grpc_slice_buffer_reset_and_unref(&ep->output_buffer); grpc_slice_buffer_reset_and_unref(&ep->output_buffer);
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, cb, DEBUG_LOCATION, cb,
grpc_set_tsi_error_result( grpc_set_tsi_error_result(GRPC_ERROR_CREATE("Wrap failed"), result));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Wrap failed"), result));
return; return;
} }

@ -199,7 +199,7 @@ void SecurityHandshaker::HandshakeFailedLocked(grpc_error_handle error) {
if (error.ok()) { if (error.ok()) {
// If we were shut down after the handshake succeeded but before an // If we were shut down after the handshake succeeded but before an
// endpoint callback was invoked, we need to generate our own error. // endpoint callback was invoked, we need to generate our own error.
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshaker shutdown"); error = GRPC_ERROR_CREATE("Handshaker shutdown");
} }
gpr_log(GPR_DEBUG, "Security handshake failed: %s", gpr_log(GPR_DEBUG, "Security handshake failed: %s",
grpc_error_std_string(error).c_str()); grpc_error_std_string(error).c_str());
@ -259,7 +259,7 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
handshaker_result_, &unused_bytes, &unused_bytes_size); handshaker_result_, &unused_bytes, &unused_bytes_size);
if (result != TSI_OK) { if (result != TSI_OK) {
HandshakeFailedLocked(grpc_set_tsi_error_result( HandshakeFailedLocked(grpc_set_tsi_error_result(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE(
"TSI handshaker result does not provide unused bytes"), "TSI handshaker result does not provide unused bytes"),
result)); result));
return; return;
@ -270,9 +270,8 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
handshaker_result_, &frame_protector_type); handshaker_result_, &frame_protector_type);
if (result != TSI_OK) { if (result != TSI_OK) {
HandshakeFailedLocked(grpc_set_tsi_error_result( HandshakeFailedLocked(grpc_set_tsi_error_result(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("TSI handshaker result does not implement "
"TSI handshaker result does not implement " "get_frame_protector_type"),
"get_frame_protector_type"),
result)); result));
return; return;
} }
@ -288,8 +287,7 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
&zero_copy_protector); &zero_copy_protector);
if (result != TSI_OK) { if (result != TSI_OK) {
HandshakeFailedLocked(grpc_set_tsi_error_result( HandshakeFailedLocked(grpc_set_tsi_error_result(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("Zero-copy frame protector creation failed"),
"Zero-copy frame protector creation failed"),
result)); result));
return; return;
} }
@ -300,10 +298,8 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
handshaker_result_, max_frame_size_ == 0 ? nullptr : &max_frame_size_, handshaker_result_, max_frame_size_ == 0 ? nullptr : &max_frame_size_,
&protector); &protector);
if (result != TSI_OK) { if (result != TSI_OK) {
HandshakeFailedLocked( HandshakeFailedLocked(grpc_set_tsi_error_result(
grpc_set_tsi_error_result(GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("Frame protector creation failed"), result));
"Frame protector creation failed"),
result));
return; return;
} }
break; break;
@ -359,7 +355,7 @@ grpc_error_handle SecurityHandshaker::CheckPeerLocked() {
tsi_handshaker_result_extract_peer(handshaker_result_, &peer); tsi_handshaker_result_extract_peer(handshaker_result_, &peer);
if (result != TSI_OK) { if (result != TSI_OK) {
return grpc_set_tsi_error_result( return grpc_set_tsi_error_result(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Peer extraction failed"), result); GRPC_ERROR_CREATE("Peer extraction failed"), result);
} }
connector_->check_peer(peer, args_->endpoint, args_->args, &auth_context_, connector_->check_peer(peer, args_->endpoint, args_->args, &auth_context_,
&on_peer_checked_); &on_peer_checked_);
@ -372,7 +368,7 @@ grpc_error_handle SecurityHandshaker::OnHandshakeNextDoneLocked(
grpc_error_handle error; grpc_error_handle error;
// Handshaker was shutdown. // Handshaker was shutdown.
if (is_shutdown_) { if (is_shutdown_) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshaker shutdown"); return GRPC_ERROR_CREATE("Handshaker shutdown");
} }
// Read more if we need to. // Read more if we need to.
if (result == TSI_INCOMPLETE_DATA) { if (result == TSI_INCOMPLETE_DATA) {
@ -393,7 +389,7 @@ grpc_error_handle SecurityHandshaker::OnHandshakeNextDoneLocked(
connector_type = security_connector->type().name(); connector_type = security_connector->type().name();
} }
return grpc_set_tsi_error_result( return grpc_set_tsi_error_result(
GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( GRPC_ERROR_CREATE(absl::StrCat(
connector_type, " handshake failed", connector_type, " handshake failed",
(tsi_handshake_error_.empty() ? "" : ": "), tsi_handshake_error_)), (tsi_handshake_error_.empty() ? "" : ": "), tsi_handshake_error_)),
result); result);
@ -486,8 +482,8 @@ void SecurityHandshaker::OnHandshakeDataReceivedFromPeerFn(
RefCountedPtr<SecurityHandshaker> h(static_cast<SecurityHandshaker*>(arg)); RefCountedPtr<SecurityHandshaker> h(static_cast<SecurityHandshaker*>(arg));
MutexLock lock(&h->mu_); MutexLock lock(&h->mu_);
if (!error.ok() || h->is_shutdown_) { if (!error.ok() || h->is_shutdown_) {
h->HandshakeFailedLocked(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( h->HandshakeFailedLocked(
"Handshake read failed", &error, 1)); GRPC_ERROR_CREATE_REFERENCING("Handshake read failed", &error, 1));
return; return;
} }
// Copy all slices received. // Copy all slices received.
@ -519,8 +515,8 @@ void SecurityHandshaker::OnHandshakeDataSentToPeerFn(void* arg,
RefCountedPtr<SecurityHandshaker> h(static_cast<SecurityHandshaker*>(arg)); RefCountedPtr<SecurityHandshaker> h(static_cast<SecurityHandshaker*>(arg));
MutexLock lock(&h->mu_); MutexLock lock(&h->mu_);
if (!error.ok() || h->is_shutdown_) { if (!error.ok() || h->is_shutdown_) {
h->HandshakeFailedLocked(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( h->HandshakeFailedLocked(
"Handshake write failed", &error, 1)); GRPC_ERROR_CREATE_REFERENCING("Handshake write failed", &error, 1));
return; return;
} }
// We may be done. // We may be done.
@ -585,8 +581,8 @@ class FailHandshaker : public Handshaker {
void DoHandshake(grpc_tcp_server_acceptor* /*acceptor*/, void DoHandshake(grpc_tcp_server_acceptor* /*acceptor*/,
grpc_closure* on_handshake_done, grpc_closure* on_handshake_done,
HandshakerArgs* args) override { HandshakerArgs* args) override {
grpc_error_handle error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( grpc_error_handle error =
"Failed to create security handshaker"); GRPC_ERROR_CREATE("Failed to create security handshaker");
grpc_endpoint_shutdown(args->endpoint, error); grpc_endpoint_shutdown(args->endpoint, error);
grpc_endpoint_destroy(args->endpoint); grpc_endpoint_destroy(args->endpoint);
args->endpoint = nullptr; args->endpoint = nullptr;

@ -208,9 +208,9 @@ static void on_md_processing_done(
if (error_details == nullptr) { if (error_details == nullptr) {
error_details = "Authentication metadata processing failed."; error_details = "Authentication metadata processing failed.";
} }
error = grpc_error_set_int( error =
GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_details), grpc_error_set_int(GRPC_ERROR_CREATE(error_details),
grpc_core::StatusIntProperty::kRpcStatus, status); grpc_core::StatusIntProperty::kRpcStatus, status);
} }
on_md_processing_done_inner(elem, consumed_md, num_consumed_md, response_md, on_md_processing_done_inner(elem, consumed_md, num_consumed_md, response_md,
num_response_md, error); num_response_md, error);

@ -35,22 +35,21 @@ const char* grpc_json_get_string_property(const grpc_core::Json& json,
grpc_error_handle* error) { grpc_error_handle* error) {
if (json.type() != grpc_core::Json::Type::OBJECT) { if (json.type() != grpc_core::Json::Type::OBJECT) {
if (error != nullptr) { if (error != nullptr) {
*error = *error = GRPC_ERROR_CREATE("JSON value is not an object");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("JSON value is not an object");
} }
return nullptr; return nullptr;
} }
auto it = json.object_value().find(prop_name); auto it = json.object_value().find(prop_name);
if (it == json.object_value().end()) { if (it == json.object_value().end()) {
if (error != nullptr) { if (error != nullptr) {
*error = GRPC_ERROR_CREATE_FROM_CPP_STRING( *error = GRPC_ERROR_CREATE(
absl::StrCat("Property ", prop_name, " not found in JSON object.")); absl::StrCat("Property ", prop_name, " not found in JSON object."));
} }
return nullptr; return nullptr;
} }
if (it->second.type() != grpc_core::Json::Type::STRING) { if (it->second.type() != grpc_core::Json::Type::STRING) {
if (error != nullptr) { if (error != nullptr) {
*error = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( *error = GRPC_ERROR_CREATE(absl::StrCat(
"Property ", prop_name, " n JSON object is not a string.")); "Property ", prop_name, " n JSON object is not a string."));
} }
return nullptr; return nullptr;

@ -309,7 +309,7 @@ void Call::CancelWithStatus(grpc_status_code status, const char* description) {
// copying 'description' is needed to ensure the grpc_call_cancel_with_status // copying 'description' is needed to ensure the grpc_call_cancel_with_status
// guarantee that can be short-lived. // guarantee that can be short-lived.
CancelWithError(grpc_error_set_int( CancelWithError(grpc_error_set_int(
grpc_error_set_str(GRPC_ERROR_CREATE_FROM_COPIED_STRING(description), grpc_error_set_str(GRPC_ERROR_CREATE(description),
StatusStrProperty::kGrpcMessage, description), StatusStrProperty::kGrpcMessage, description),
StatusIntProperty::kRpcStatus, status)); StatusIntProperty::kRpcStatus, status));
} }
@ -627,7 +627,7 @@ grpc_error_handle FilterStackCall::Create(grpc_call_create_args* args,
grpc_error_handle new_err) { grpc_error_handle new_err) {
if (new_err.ok()) return; if (new_err.ok()) return;
if (composite->ok()) { if (composite->ok()) {
*composite = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Call creation failed"); *composite = GRPC_ERROR_CREATE("Call creation failed");
} }
*composite = grpc_error_add_child(*composite, new_err); *composite = grpc_error_add_child(*composite, new_err);
}; };
@ -1018,8 +1018,7 @@ void FilterStackCall::RecvTrailingFilter(grpc_metadata_batch* b,
if (status_code != GRPC_STATUS_OK) { if (status_code != GRPC_STATUS_OK) {
char* peer = GetPeer(); char* peer = GetPeer();
error = grpc_error_set_int( error = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_CPP_STRING( GRPC_ERROR_CREATE(absl::StrCat("Error received from peer ", peer)),
absl::StrCat("Error received from peer ", peer)),
StatusIntProperty::kRpcStatus, static_cast<intptr_t>(status_code)); StatusIntProperty::kRpcStatus, static_cast<intptr_t>(status_code));
gpr_free(peer); gpr_free(peer);
} }
@ -1036,9 +1035,9 @@ void FilterStackCall::RecvTrailingFilter(grpc_metadata_batch* b,
} else { } else {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"Received trailing metadata with no error and no status"); "Received trailing metadata with no error and no status");
SetFinalStatus(grpc_error_set_int( SetFinalStatus(grpc_error_set_int(GRPC_ERROR_CREATE("No status received"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("No status received"), StatusIntProperty::kRpcStatus,
StatusIntProperty::kRpcStatus, GRPC_STATUS_UNKNOWN)); GRPC_STATUS_UNKNOWN));
} }
} }
PublishAppMetadata(b, true); PublishAppMetadata(b, true);
@ -1112,7 +1111,7 @@ void FilterStackCall::BatchControl::PostCompletion() {
if (op_.send_message) { if (op_.send_message) {
if (op_.payload->send_message.stream_write_closed && error.ok()) { if (op_.payload->send_message.stream_write_closed && error.ok()) {
error = grpc_error_add_child( error = grpc_error_add_child(
error, GRPC_ERROR_CREATE_FROM_STATIC_STRING( error, GRPC_ERROR_CREATE(
"Attempt to send message after stream was closed.")); "Attempt to send message after stream was closed."));
} }
call->sending_message_ = false; call->sending_message_ = false;
@ -1552,8 +1551,7 @@ grpc_call_error FilterStackCall::StartBatch(const grpc_op* ops, size_t nops,
op->data.send_status_from_server.status == GRPC_STATUS_OK op->data.send_status_from_server.status == GRPC_STATUS_OK
? absl::OkStatus() ? absl::OkStatus()
: grpc_error_set_int( : grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ERROR_CREATE("Server returned error"),
"Server returned error"),
StatusIntProperty::kRpcStatus, StatusIntProperty::kRpcStatus,
static_cast<intptr_t>( static_cast<intptr_t>(
op->data.send_status_from_server.status)); op->data.send_status_from_server.status));

@ -429,8 +429,7 @@ void grpc_channel_destroy_internal(grpc_channel* c_channel) {
grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_transport_op* op = grpc_make_transport_op(nullptr);
grpc_channel_element* elem; grpc_channel_element* elem;
GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (c_channel)); GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (c_channel));
op->disconnect_with_error = op->disconnect_with_error = GRPC_ERROR_CREATE("Channel Destroyed");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Destroyed");
elem = grpc_channel_stack_element(channel->channel_stack(), 0); elem = grpc_channel_stack_element(channel->channel_stack(), 0);
elem->filter->start_transport_op(elem, op); elem->filter->start_transport_op(elem, op);
} }

@ -96,11 +96,11 @@ bool LameClientFilter::StartTransportOp(grpc_transport_op* op) {
} }
if (op->send_ping.on_initiate != nullptr) { if (op->send_ping.on_initiate != nullptr) {
ExecCtx::Run(DEBUG_LOCATION, op->send_ping.on_initiate, ExecCtx::Run(DEBUG_LOCATION, op->send_ping.on_initiate,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel")); GRPC_ERROR_CREATE("lame client channel"));
} }
if (op->send_ping.on_ack != nullptr) { if (op->send_ping.on_ack != nullptr) {
ExecCtx::Run(DEBUG_LOCATION, op->send_ping.on_ack, ExecCtx::Run(DEBUG_LOCATION, op->send_ping.on_ack,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel")); GRPC_ERROR_CREATE("lame client channel"));
} }
if (op->on_consumed != nullptr) { if (op->on_consumed != nullptr) {
ExecCtx::Run(DEBUG_LOCATION, op->on_consumed, absl::OkStatus()); ExecCtx::Run(DEBUG_LOCATION, op->on_consumed, absl::OkStatus());

@ -471,9 +471,8 @@ class ChannelBroadcaster {
grpc_channel_element* elem; grpc_channel_element* elem;
op->goaway_error = op->goaway_error =
send_goaway send_goaway
? grpc_error_set_int( ? grpc_error_set_int(GRPC_ERROR_CREATE("Server shutdown"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"), StatusIntProperty::kRpcStatus, GRPC_STATUS_OK)
StatusIntProperty::kRpcStatus, GRPC_STATUS_OK)
: absl::OkStatus(); : absl::OkStatus();
sc->slice = grpc_slice_from_copied_string("Server shutdown"); sc->slice = grpc_slice_from_copied_string("Server shutdown");
op->disconnect_with_error = send_disconnect; op->disconnect_with_error = send_disconnect;
@ -709,8 +708,7 @@ void Server::MaybeFinishShutdown() {
} }
{ {
MutexLock lock(&mu_call_); MutexLock lock(&mu_call_);
KillPendingWorkLocked( KillPendingWorkLocked(GRPC_ERROR_CREATE("Server Shutdown"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
} }
if (!channels_.empty() || listeners_destroyed_ < listeners_.size()) { if (!channels_.empty() || listeners_destroyed_ < listeners_.size()) {
if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME),
@ -807,8 +805,7 @@ void Server::ShutdownAndNotify(grpc_completion_queue* cq, void* tag) {
// Collect all unregistered then registered calls. // Collect all unregistered then registered calls.
{ {
MutexLock lock(&mu_call_); MutexLock lock(&mu_call_);
KillPendingWorkLocked( KillPendingWorkLocked(GRPC_ERROR_CREATE("Server Shutdown"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
} }
await_requests = ShutdownUnrefOnShutdownCall(); await_requests = ShutdownUnrefOnShutdownCall();
} }
@ -844,8 +841,7 @@ void Server::CancelAllCalls() {
broadcaster.FillChannelsLocked(GetChannelsLocked()); broadcaster.FillChannelsLocked(GetChannelsLocked());
} }
broadcaster.BroadcastShutdown( broadcaster.BroadcastShutdown(
/*send_goaway=*/false, /*send_goaway=*/false, GRPC_ERROR_CREATE("Cancelling all calls"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls"));
} }
void Server::SendGoaways() { void Server::SendGoaways() {
@ -903,8 +899,7 @@ grpc_call_error Server::ValidateServerRequestAndCq(
grpc_call_error Server::QueueRequestedCall(size_t cq_idx, RequestedCall* rc) { grpc_call_error Server::QueueRequestedCall(size_t cq_idx, RequestedCall* rc) {
if (ShutdownCalled()) { if (ShutdownCalled()) {
FailCall(cq_idx, rc, FailCall(cq_idx, rc, GRPC_ERROR_CREATE("Server Shutdown"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
return GRPC_CALL_OK; return GRPC_CALL_OK;
} }
RequestMatcherInterface* rm; RequestMatcherInterface* rm;
@ -1056,8 +1051,7 @@ void Server::ChannelData::InitTransport(RefCountedPtr<Server> server,
op->set_accept_stream_user_data = this; op->set_accept_stream_user_data = this;
op->start_connectivity_watch = MakeOrphanable<ConnectivityWatcher>(this); op->start_connectivity_watch = MakeOrphanable<ConnectivityWatcher>(this);
if (server_->ShutdownCalled()) { if (server_->ShutdownCalled()) {
op->disconnect_with_error = op->disconnect_with_error = GRPC_ERROR_CREATE("Server shutdown");
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown");
} }
grpc_transport_perform_op(transport, op); grpc_transport_perform_op(transport, op);
} }
@ -1367,8 +1361,8 @@ void Server::CallData::RecvInitialMetadataReady(void* arg,
} else { } else {
/* Pass the error reference to calld->recv_initial_metadata_error */ /* Pass the error reference to calld->recv_initial_metadata_error */
grpc_error_handle src_error = error; grpc_error_handle src_error = error;
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( error = GRPC_ERROR_CREATE_REFERENCING("Missing :authority or :path",
"Missing :authority or :path", &src_error, 1); &src_error, 1);
calld->recv_initial_metadata_error_ = error; calld->recv_initial_metadata_error_ = error;
} }
grpc_closure* closure = calld->original_recv_initial_metadata_ready_; grpc_closure* closure = calld->original_recv_initial_metadata_ready_;

@ -43,7 +43,7 @@ static grpc_error_handle conforms_to(const grpc_slice& slice,
reinterpret_cast<const char*> GRPC_SLICE_START_PTR(slice), reinterpret_cast<const char*> GRPC_SLICE_START_PTR(slice),
GRPC_SLICE_LENGTH(slice), GPR_DUMP_HEX | GPR_DUMP_ASCII, &len)); GRPC_SLICE_LENGTH(slice), GPR_DUMP_HEX | GPR_DUMP_ASCII, &len));
grpc_error_handle error = grpc_error_set_str( grpc_error_handle error = grpc_error_set_str(
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(err_desc), grpc_error_set_int(GRPC_ERROR_CREATE(err_desc),
grpc_core::StatusIntProperty::kOffset, grpc_core::StatusIntProperty::kOffset,
p - GRPC_SLICE_START_PTR(slice)), p - GRPC_SLICE_START_PTR(slice)),
grpc_core::StatusStrProperty::kRawBytes, grpc_core::StatusStrProperty::kRawBytes,
@ -75,16 +75,13 @@ constexpr LegalHeaderKeyBits g_legal_header_key_bits;
grpc_error_handle grpc_validate_header_key_is_legal(const grpc_slice& slice) { grpc_error_handle grpc_validate_header_key_is_legal(const grpc_slice& slice) {
if (GRPC_SLICE_LENGTH(slice) == 0) { if (GRPC_SLICE_LENGTH(slice) == 0) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Metadata keys cannot be zero length");
"Metadata keys cannot be zero length");
} }
if (GRPC_SLICE_LENGTH(slice) > UINT32_MAX) { if (GRPC_SLICE_LENGTH(slice) > UINT32_MAX) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Metadata keys cannot be larger than UINT32_MAX");
"Metadata keys cannot be larger than UINT32_MAX");
} }
if (GRPC_SLICE_START_PTR(slice)[0] == ':') { if (GRPC_SLICE_START_PTR(slice)[0] == ':') {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE("Metadata keys cannot start with :");
"Metadata keys cannot start with :");
} }
return conforms_to(slice, g_legal_header_key_bits, "Illegal header key"); return conforms_to(slice, g_legal_header_key_bits, "Illegal header key");
} }

@ -150,10 +150,9 @@ grpc_error_handle absl_status_to_grpc_error(absl::Status status) {
if (status.ok()) { if (status.ok()) {
return absl::OkStatus(); return absl::OkStatus();
} }
return grpc_error_set_int( return grpc_error_set_int(GRPC_ERROR_CREATE(status.message()),
GRPC_ERROR_CREATE_FROM_STRING_VIEW(status.message()), grpc_core::StatusIntProperty::kRpcStatus,
grpc_core::StatusIntProperty::kRpcStatus, static_cast<grpc_status_code>(status.code()));
static_cast<grpc_status_code>(status.code()));
} }
bool grpc_error_has_clear_grpc_status(grpc_error_handle error) { bool grpc_error_has_clear_grpc_status(grpc_error_handle error) {

@ -101,7 +101,7 @@ bool HandshakeManager::CallNextHandshakerLocked(grpc_error_handle error) {
if (!error.ok() || is_shutdown_ || args_.exit_early || if (!error.ok() || is_shutdown_ || args_.exit_early ||
index_ == handshakers_.size()) { index_ == handshakers_.size()) {
if (error.ok() && is_shutdown_) { if (error.ok() && is_shutdown_) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("handshaker shutdown"); error = GRPC_ERROR_CREATE("handshaker shutdown");
// It is possible that the endpoint has already been destroyed by // It is possible that the endpoint has already been destroyed by
// a shutdown call while this callback was sitting on the ExecCtx // a shutdown call while this callback was sitting on the ExecCtx
// with no error. // with no error.
@ -163,7 +163,7 @@ void HandshakeManager::CallNextHandshakerFn(void* arg,
void HandshakeManager::OnTimeoutFn(void* arg, grpc_error_handle error) { void HandshakeManager::OnTimeoutFn(void* arg, grpc_error_handle error) {
auto* mgr = static_cast<HandshakeManager*>(arg); auto* mgr = static_cast<HandshakeManager*>(arg);
if (error.ok()) { // Timer fired, rather than being cancelled if (error.ok()) { // Timer fired, rather than being cancelled
mgr->Shutdown(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out")); mgr->Shutdown(GRPC_ERROR_CREATE("Handshake timed out"));
} }
mgr->Unref(); mgr->Unref();
} }

@ -127,7 +127,7 @@ void HttpConnectHandshaker::HandshakeFailedLocked(grpc_error_handle error) {
// If we were shut down after an endpoint operation succeeded but // If we were shut down after an endpoint operation succeeded but
// before the endpoint callback was invoked, we need to generate our // before the endpoint callback was invoked, we need to generate our
// own error. // own error.
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshaker shutdown"); error = GRPC_ERROR_CREATE("Handshaker shutdown");
} }
if (!is_shutdown_) { if (!is_shutdown_) {
// TODO(ctiller): It is currently necessary to shutdown endpoints // TODO(ctiller): It is currently necessary to shutdown endpoints
@ -258,9 +258,8 @@ void HttpConnectHandshaker::OnReadDone(void* arg, grpc_error_handle error) {
// Make sure we got a 2xx response. // Make sure we got a 2xx response.
if (handshaker->http_response_.status < 200 || if (handshaker->http_response_.status < 200 ||
handshaker->http_response_.status >= 300) { handshaker->http_response_.status >= 300) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING( error = GRPC_ERROR_CREATE(absl::StrCat("HTTP proxy returned response code ",
absl::StrCat("HTTP proxy returned response code ", handshaker->http_response_.status));
handshaker->http_response_.status));
handshaker->HandshakeFailedLocked(error); handshaker->HandshakeFailedLocked(error);
goto done; goto done;
} }

@ -113,8 +113,7 @@ void TCPConnectHandshaker::Shutdown(grpc_error_handle /*why*/) {
// the necessary clean up. // the necessary clean up.
if (on_handshake_done_ != nullptr) { if (on_handshake_done_ != nullptr) {
CleanupArgsForFailureLocked(); CleanupArgsForFailureLocked();
FinishLocked( FinishLocked(GRPC_ERROR_CREATE("tcp handshaker shutdown"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("tcp handshaker shutdown"));
} }
} }
} }
@ -133,8 +132,7 @@ void TCPConnectHandshaker::DoHandshake(grpc_tcp_server_acceptor* /*acceptor*/,
args->args.GetString(GRPC_ARG_TCP_HANDSHAKER_RESOLVED_ADDRESS).value()); args->args.GetString(GRPC_ARG_TCP_HANDSHAKER_RESOLVED_ADDRESS).value());
if (!uri.ok() || !grpc_parse_uri(*uri, &addr_)) { if (!uri.ok() || !grpc_parse_uri(*uri, &addr_)) {
MutexLock lock(&mu_); MutexLock lock(&mu_);
FinishLocked(GRPC_ERROR_CREATE_FROM_STATIC_STRING( FinishLocked(GRPC_ERROR_CREATE("Resolved address in invalid format"));
"Resolved address in invalid format"));
return; return;
} }
bind_endpoint_to_pollset_ = bind_endpoint_to_pollset_ =
@ -168,7 +166,7 @@ void TCPConnectHandshaker::Connected(void* arg, grpc_error_handle error) {
MutexLock lock(&self->mu_); MutexLock lock(&self->mu_);
if (!error.ok() || self->shutdown_) { if (!error.ok() || self->shutdown_) {
if (error.ok()) { if (error.ok()) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("tcp handshaker shutdown"); error = GRPC_ERROR_CREATE("tcp handshaker shutdown");
} }
if (self->endpoint_to_destroy_ != nullptr) { if (self->endpoint_to_destroy_ != nullptr) {
grpc_endpoint_shutdown(self->endpoint_to_destroy_, error); grpc_endpoint_shutdown(self->endpoint_to_destroy_, error);

@ -90,8 +90,7 @@ static void set_read_done(void* arg, grpc_error_handle /*error*/) {
/* shutdown client */ /* shutdown client */
static void shutdown_client(grpc_endpoint** client_fd) { static void shutdown_client(grpc_endpoint** client_fd) {
if (*client_fd != nullptr) { if (*client_fd != nullptr) {
grpc_endpoint_shutdown( grpc_endpoint_shutdown(*client_fd, GRPC_ERROR_CREATE("Forced Disconnect"));
*client_fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect"));
grpc_endpoint_destroy(*client_fd); grpc_endpoint_destroy(*client_fd);
grpc_core::ExecCtx::Get()->Flush(); grpc_core::ExecCtx::Get()->Flush();
*client_fd = nullptr; *client_fd = nullptr;

@ -343,8 +343,7 @@ static void run_test(bool http2_response, bool send_settings,
/* Proof that the server accepted the TCP connection. */ /* Proof that the server accepted the TCP connection. */
GPR_ASSERT(state.connection_attempt_made == true); GPR_ASSERT(state.connection_attempt_made == true);
/* clean up */ /* clean up */
grpc_endpoint_shutdown(state.tcp, grpc_endpoint_shutdown(state.tcp, GRPC_ERROR_CREATE("Test Shutdown"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
grpc_endpoint_destroy(state.tcp); grpc_endpoint_destroy(state.tcp);
cleanup_rpc(); cleanup_rpc();
grpc_core::ExecCtx::Get()->Flush(); grpc_core::ExecCtx::Get()->Flush();

@ -503,8 +503,8 @@ static void on_read_request_done_locked(void* arg, grpc_error_handle error) {
} }
// Make sure we got a CONNECT request. // Make sure we got a CONNECT request.
if (strcmp(conn->http_request.method, "CONNECT") != 0) { if (strcmp(conn->http_request.method, "CONNECT") != 0) {
error = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat( error = GRPC_ERROR_CREATE(absl::StrCat("HTTP proxy got request method ",
"HTTP proxy got request method ", conn->http_request.method)); conn->http_request.method));
proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request",
error); error);
return; return;
@ -524,7 +524,7 @@ static void on_read_request_done_locked(void* arg, grpc_error_handle error) {
} }
if (!client_authenticated) { if (!client_authenticated) {
const char* msg = "HTTP Connect could not verify authentication"; const char* msg = "HTTP Connect could not verify authentication";
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(msg); error = GRPC_ERROR_CREATE(msg);
proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request",
error); error);
return; return;

@ -126,9 +126,9 @@ static void finish_resolve(void* arg, grpc_error_handle error) {
->emplace_back(fake_resolved_address, grpc_core::ChannelArgs()); ->emplace_back(fake_resolved_address, grpc_core::ChannelArgs());
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, absl::OkStatus()); grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, absl::OkStatus());
} else { } else {
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_done, grpc_core::ExecCtx::Run(
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( DEBUG_LOCATION, r->on_done,
"Resolution failed", &error, 1)); GRPC_ERROR_CREATE_REFERENCING("Resolution failed", &error, 1));
} }
gpr_free(r->addr); gpr_free(r->addr);
@ -299,9 +299,8 @@ static void sched_connect(grpc_closure* closure, grpc_endpoint** ep,
gpr_timespec deadline) { gpr_timespec deadline) {
if (gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) < 0) { if (gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) < 0) {
*ep = nullptr; *ep = nullptr;
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure,
DEBUG_LOCATION, closure, GRPC_ERROR_CREATE("Connect deadline exceeded"));
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connect deadline exceeded"));
return; return;
} }

@ -184,7 +184,7 @@ static grpc_ares_request* my_dns_lookup_ares(
gpr_mu_lock(&g_mu); gpr_mu_lock(&g_mu);
if (g_resolve_port < 0) { if (g_resolve_port < 0) {
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Failure"); error = GRPC_ERROR_CREATE("Forced Failure");
} else { } else {
*addresses = std::make_unique<grpc_core::ServerAddressList>(); *addresses = std::make_unique<grpc_core::ServerAddressList>();
grpc_sockaddr_in sa; grpc_sockaddr_in sa;

@ -209,7 +209,7 @@ static void recv_im_ready(void* arg, grpc_error_handle error) {
call_data* calld = static_cast<call_data*>(elem->call_data); call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_core::Closure::Run( grpc_core::Closure::Run(
DEBUG_LOCATION, calld->recv_im_ready, DEBUG_LOCATION, calld->recv_im_ready,
grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING(
"Failure that's not preventable.", &error, 1), "Failure that's not preventable.", &error, 1),
grpc_core::StatusIntProperty::kRpcStatus, grpc_core::StatusIntProperty::kRpcStatus,
GRPC_STATUS_PERMISSION_DENIED)); GRPC_STATUS_PERMISSION_DENIED));

@ -426,9 +426,9 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) {
static grpc_error_handle init_call_elem( static grpc_error_handle init_call_elem(
grpc_call_element* /*elem*/, const grpc_call_element_args* /*args*/) { grpc_call_element* /*elem*/, const grpc_call_element_args* /*args*/) {
return grpc_error_set_int( return grpc_error_set_int(GRPC_ERROR_CREATE("access denied"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("access denied"), grpc_core::StatusIntProperty::kRpcStatus,
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_PERMISSION_DENIED); GRPC_STATUS_PERMISSION_DENIED);
} }
static void destroy_call_elem(grpc_call_element* /*elem*/, static void destroy_call_elem(grpc_call_element* /*elem*/,
@ -439,7 +439,7 @@ static grpc_error_handle init_channel_elem(
grpc_channel_element* /*elem*/, grpc_channel_element_args* /*args*/) { grpc_channel_element* /*elem*/, grpc_channel_element_args* /*args*/) {
if (g_channel_filter_init_failure) { if (g_channel_filter_init_failure) {
return grpc_error_set_int( return grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test channel filter init error"), GRPC_ERROR_CREATE("Test channel filter init error"),
grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_INVALID_ARGUMENT); grpc_core::StatusIntProperty::kRpcStatus, GRPC_STATUS_INVALID_ARGUMENT);
} }
return absl::OkStatus(); return absl::OkStatus();

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save