Skip to content

Commit 00a5f74

Browse files
authored
Revert "Import cronet net error list and modify grpc-cronet error message."
1 parent 7bf8260 commit 00a5f74

File tree

7 files changed

+112
-1036
lines changed

7 files changed

+112
-1036
lines changed

gRPC-Core.podspec

+1-2
Original file line numberDiff line numberDiff line change
@@ -1603,8 +1603,7 @@ Pod::Spec.new do |s|
16031603
'src/core/ext/transport/cronet/transport/cronet_status.h',
16041604
'src/core/ext/transport/cronet/transport/cronet_transport.cc',
16051605
'src/core/ext/transport/cronet/transport/cronet_transport.h',
1606-
'third_party/objective_c/Cronet/bidirectional_stream_c.h',
1607-
'third_party/objective_c/Cronet/net_error_list.h'
1606+
'third_party/objective_c/Cronet/bidirectional_stream_c.h'
16081607
end
16091608

16101609
s.subspec 'Tests' do |ss|

src/core/ext/transport/cronet/transport/cronet_status.cc

+66-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,72 @@
2020

2121
#include "src/core/ext/transport/cronet/transport/cronet_status.h"
2222

23-
const char* cronet_net_error_as_string(cronet_net_error_code net_error) {
24-
switch (net_error) {
25-
case OK:
26-
return "OK";
27-
#define NET_ERROR(label, value) \
28-
case CRONET_NET_ERROR_##label: \
29-
return #label;
30-
#include "third_party/objective_c/Cronet/net_error_list.h"
31-
#undef NET_ERROR
23+
const char* cronet_status_as_string(cronet_status_code status) {
24+
switch (status) {
25+
case CRONET_STATUS_SUCCESS:
26+
return "CRONET_STATUS_SUCCESS.";
27+
case CRONET_STATUS_ILLEGAL_ARGUMENT:
28+
return "CRONET_STATUS_ILLEGAL_ARGUMENT.";
29+
case CRONET_STATUS_ILLEGAL_ARGUMENT_STORAGE_PATH_MUST_EXIST:
30+
return "CRONET_STATUS_ILLEGAL_ARGUMENT_STORAGE_PATH_MUST_EXIST.";
31+
case CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_PIN:
32+
return "CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_PIN.";
33+
case CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HOSTNAME:
34+
return "CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HOSTNAME.";
35+
case CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HTTP_METHOD:
36+
return "CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HTTP_METHOD.";
37+
case CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HTTP_HEADER:
38+
return "CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HTTP_HEADER.";
39+
case CRONET_STATUS_ILLEGAL_STATE:
40+
return "CRONET_STATUS_ILLEGAL_STATE.";
41+
case CRONET_STATUS_ILLEGAL_STATE_STORAGE_PATH_IN_USE:
42+
return "CRONET_STATUS_ILLEGAL_STATE_STORAGE_PATH_IN_USE.";
43+
case CRONET_STATUS_ILLEGAL_STATE_CANNOT_SHUTDOWN_ENGINE_FROM_NETWORK_THREAD:
44+
return "CRONET_STATUS_ILLEGAL_STATE_CANNOT_SHUTDOWN_ENGINE_FROM_NETWORK_"
45+
"THREAD.";
46+
case CRONET_STATUS_ILLEGAL_STATE_ENGINE_ALREADY_STARTED:
47+
return "CRONET_STATUS_ILLEGAL_STATE_ENGINE_ALREADY_STARTED.";
48+
case CRONET_STATUS_ILLEGAL_STATE_REQUEST_ALREADY_STARTED:
49+
return "CRONET_STATUS_ILLEGAL_STATE_REQUEST_ALREADY_STARTED.";
50+
case CRONET_STATUS_ILLEGAL_STATE_REQUEST_NOT_INITIALIZED:
51+
return "CRONET_STATUS_ILLEGAL_STATE_REQUEST_NOT_INITIALIZED.";
52+
case CRONET_STATUS_ILLEGAL_STATE_REQUEST_ALREADY_INITIALIZED:
53+
return "CRONET_STATUS_ILLEGAL_STATE_REQUEST_ALREADY_INITIALIZED.";
54+
case CRONET_STATUS_ILLEGAL_STATE_REQUEST_NOT_STARTED:
55+
return "CRONET_STATUS_ILLEGAL_STATE_REQUEST_NOT_STARTED.";
56+
case CRONET_STATUS_ILLEGAL_STATE_UNEXPECTED_REDIRECT:
57+
return "CRONET_STATUS_ILLEGAL_STATE_UNEXPECTED_REDIRECT.";
58+
case CRONET_STATUS_ILLEGAL_STATE_UNEXPECTED_READ:
59+
return "CRONET_STATUS_ILLEGAL_STATE_UNEXPECTED_READ.";
60+
case CRONET_STATUS_ILLEGAL_STATE_READ_FAILED:
61+
return "CRONET_STATUS_ILLEGAL_STATE_READ_FAILED.";
62+
case CRONET_STATUS_NULL_POINTER:
63+
return "CRONET_STATUS_NULL_POINTER.";
64+
case CRONET_STATUS_NULL_POINTER_HOSTNAME:
65+
return "CRONET_STATUS_NULL_POINTER_HOSTNAME.";
66+
case CRONET_STATUS_NULL_POINTER_SHA256_PINS:
67+
return "CRONET_STATUS_NULL_POINTER_SHA256_PINS.";
68+
case CRONET_STATUS_NULL_POINTER_EXPIRATION_DATE:
69+
return "CRONET_STATUS_NULL_POINTER_EXPIRATION_DATE.";
70+
case CRONET_STATUS_NULL_POINTER_ENGINE:
71+
return "CRONET_STATUS_NULL_POINTER_ENGINE.";
72+
case CRONET_STATUS_NULL_POINTER_URL:
73+
return "CRONET_STATUS_NULL_POINTER_URL.";
74+
case CRONET_STATUS_NULL_POINTER_CALLBACK:
75+
return "CRONET_STATUS_NULL_POINTER_CALLBACK.";
76+
case CRONET_STATUS_NULL_POINTER_EXECUTOR:
77+
return "CRONET_STATUS_NULL_POINTER_EXECUTOR.";
78+
case CRONET_STATUS_NULL_POINTER_METHOD:
79+
return "CRONET_STATUS_NULL_POINTER_METHOD.";
80+
case CRONET_STATUS_NULL_POINTER_HEADER_NAME:
81+
return "CRONET_STATUS_NULL_POINTER_HEADER_NAME.";
82+
case CRONET_STATUS_NULL_POINTER_HEADER_VALUE:
83+
return "CRONET_STATUS_NULL_POINTER_HEADER_VALUE";
84+
case CRONET_STATUS_NULL_POINTER_PARAMS:
85+
return "CRONET_STATUS_NULL_POINTER_PARAMS.";
86+
case CRONET_STATUS_NULL_POINTER_REQUEST_FINISHED_INFO_LISTENER_EXECUTOR:
87+
return "CRONET_STATUS_NULL_POINTER_REQUEST_FINISHED_INFO_LISTENER_"
88+
"EXECUTOR.";
3289
}
3390
return "UNAVAILABLE.";
3491
}

src/core/ext/transport/cronet/transport/cronet_status.h

+34-8
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,41 @@
1919
#ifndef GRPC_CORE_EXT_TRANSPORT_CRONET_TRANSPORT_CRONET_STATUS_H
2020
#define GRPC_CORE_EXT_TRANSPORT_CRONET_TRANSPORT_CRONET_STATUS_H
2121

22-
#include <grpc/impl/codegen/port_platform.h>
23-
24-
enum cronet_net_error_code {
25-
OK = 0,
26-
#define NET_ERROR(label, value) CRONET_NET_ERROR_##label = value,
27-
#include "third_party/objective_c/Cronet/net_error_list.h"
28-
#undef NET_ERROR
22+
/* HTTP/2 error codes are mapped to the following cronet net error codes */
23+
enum cronet_status_code {
24+
CRONET_STATUS_SUCCESS = 0,
25+
CRONET_STATUS_ILLEGAL_ARGUMENT = -100,
26+
CRONET_STATUS_ILLEGAL_ARGUMENT_STORAGE_PATH_MUST_EXIST = -101,
27+
CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_PIN = -102,
28+
CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HOSTNAME = -103,
29+
CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HTTP_METHOD = -104,
30+
CRONET_STATUS_ILLEGAL_ARGUMENT_INVALID_HTTP_HEADER = -105,
31+
CRONET_STATUS_ILLEGAL_STATE = -200,
32+
CRONET_STATUS_ILLEGAL_STATE_STORAGE_PATH_IN_USE = -201,
33+
CRONET_STATUS_ILLEGAL_STATE_CANNOT_SHUTDOWN_ENGINE_FROM_NETWORK_THREAD = -202,
34+
CRONET_STATUS_ILLEGAL_STATE_ENGINE_ALREADY_STARTED = -203,
35+
CRONET_STATUS_ILLEGAL_STATE_REQUEST_ALREADY_STARTED = -204,
36+
CRONET_STATUS_ILLEGAL_STATE_REQUEST_NOT_INITIALIZED = -205,
37+
CRONET_STATUS_ILLEGAL_STATE_REQUEST_ALREADY_INITIALIZED = -206,
38+
CRONET_STATUS_ILLEGAL_STATE_REQUEST_NOT_STARTED = -207,
39+
CRONET_STATUS_ILLEGAL_STATE_UNEXPECTED_REDIRECT = -208,
40+
CRONET_STATUS_ILLEGAL_STATE_UNEXPECTED_READ = -209,
41+
CRONET_STATUS_ILLEGAL_STATE_READ_FAILED = -210,
42+
CRONET_STATUS_NULL_POINTER = -300,
43+
CRONET_STATUS_NULL_POINTER_HOSTNAME = -301,
44+
CRONET_STATUS_NULL_POINTER_SHA256_PINS = -302,
45+
CRONET_STATUS_NULL_POINTER_EXPIRATION_DATE = -303,
46+
CRONET_STATUS_NULL_POINTER_ENGINE = -304,
47+
CRONET_STATUS_NULL_POINTER_URL = -305,
48+
CRONET_STATUS_NULL_POINTER_CALLBACK = -306,
49+
CRONET_STATUS_NULL_POINTER_EXECUTOR = -307,
50+
CRONET_STATUS_NULL_POINTER_METHOD = -308,
51+
CRONET_STATUS_NULL_POINTER_HEADER_NAME = -309,
52+
CRONET_STATUS_NULL_POINTER_HEADER_VALUE = -310,
53+
CRONET_STATUS_NULL_POINTER_PARAMS = -311,
54+
CRONET_STATUS_NULL_POINTER_REQUEST_FINISHED_INFO_LISTENER_EXECUTOR = -312,
2955
};
3056

31-
const char* cronet_net_error_as_string(cronet_net_error_code net_error);
57+
const char* cronet_status_as_string(cronet_status_code status);
3258

3359
#endif /* GRPC_CORE_EXT_TRANSPORT_CRONET_TRANSPORT_CRONET_STATUS_H */

src/core/ext/transport/cronet/transport/cronet_transport.cc

+10-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <string>
2424

2525
#include "absl/strings/str_cat.h"
26-
#include "absl/strings/str_format.h"
2726

2827
#include <grpc/slice_buffer.h>
2928
#include <grpc/support/alloc.h>
@@ -164,7 +163,7 @@ struct op_state {
164163
bool pending_send_message = false;
165164
/* User requested RECV_TRAILING_METADATA */
166165
bool pending_recv_trailing_metadata = false;
167-
cronet_net_error_code net_error = OK;
166+
cronet_status_code net_error = CRONET_STATUS_SUCCESS;
168167
grpc_error* cancel_error = GRPC_ERROR_NONE;
169168
/* data structure for storing data coming from server */
170169
struct read_state rs;
@@ -306,14 +305,8 @@ static void read_grpc_header(stream_obj* s) {
306305
s->state.rs.remaining_bytes);
307306
}
308307

309-
static grpc_error* make_error_with_desc(int error_code,
310-
int cronet_internal_error_code,
311-
const char* desc) {
312-
std::string error_message =
313-
absl::StrFormat("Cronet error code:%d, Cronet error detail:%s",
314-
cronet_internal_error_code, desc);
315-
grpc_error* error =
316-
GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_message.c_str());
308+
static grpc_error* make_error_with_desc(int error_code, const char* desc) {
309+
grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc);
317310
error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, error_code);
318311
return error;
319312
}
@@ -441,7 +434,7 @@ static void on_failed(bidirectional_stream* stream, int net_error) {
441434
gpr_mu_lock(&s->mu);
442435
bidirectional_stream_destroy(s->cbs);
443436
s->state.state_callback_received[OP_FAILED] = true;
444-
s->state.net_error = static_cast<cronet_net_error_code>(net_error);
437+
s->state.net_error = static_cast<cronet_status_code>(net_error);
445438
s->cbs = nullptr;
446439
if (s->header_array.headers) {
447440
gpr_free(s->header_array.headers);
@@ -1304,9 +1297,9 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
13041297
if (stream_state->state_op_done[OP_CANCEL_ERROR]) {
13051298
error = GRPC_ERROR_REF(stream_state->cancel_error);
13061299
} else if (stream_state->state_callback_received[OP_FAILED]) {
1307-
const char* desc = cronet_net_error_as_string(stream_state->net_error);
1308-
error = make_error_with_desc(GRPC_STATUS_UNAVAILABLE,
1309-
stream_state->net_error, desc);
1300+
const char* error_message =
1301+
cronet_status_as_string(stream_state->net_error);
1302+
error = make_error_with_desc(GRPC_STATUS_UNAVAILABLE, error_message);
13101303
} else if (oas->s->state.rs.trailing_metadata_valid) {
13111304
grpc_chttp2_incoming_metadata_buffer_publish(
13121305
&oas->s->state.rs.trailing_metadata,
@@ -1343,11 +1336,11 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
13431336
}
13441337
} else if (stream_state->state_callback_received[OP_FAILED]) {
13451338
if (stream_op->on_complete) {
1346-
const char* desc = cronet_net_error_as_string(stream_state->net_error);
1339+
const char* error_message =
1340+
cronet_status_as_string(stream_state->net_error);
13471341
grpc_core::ExecCtx::Run(
13481342
DEBUG_LOCATION, stream_op->on_complete,
1349-
make_error_with_desc(GRPC_STATUS_UNAVAILABLE,
1350-
stream_state->net_error, desc));
1343+
make_error_with_desc(GRPC_STATUS_UNAVAILABLE, error_message));
13511344
}
13521345
} else {
13531346
/* All actions in this stream_op are complete. Call the on_complete

templates/gRPC-Core.podspec.template

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@
8181
'src/core/ext/transport/cronet/transport/cronet_status.h',
8282
'src/core/ext/transport/cronet/transport/cronet_transport.cc',
8383
'src/core/ext/transport/cronet/transport/cronet_transport.h',
84-
'third_party/objective_c/Cronet/bidirectional_stream_c.h',
85-
'third_party/objective_c/Cronet/net_error_list.h'
84+
'third_party/objective_c/Cronet/bidirectional_stream_c.h'
8685
]
8786

8887
grpc_cronet_files = list(sorted(grpc_cronet_extra_impl_files))

third_party/objective_c/Cronet/BUILD

-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ cc_library(
2323
name = "cronet_c_for_grpc",
2424
hdrs = [
2525
"bidirectional_stream_c.h",
26-
"net_error_list.h",
2726
],
2827
)

0 commit comments

Comments
 (0)