Skip to content

Commit b7d1251

Browse files
authored
Add details to connection option validation failure logging (#279)
1 parent 183d505 commit b7d1251

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

source/connection.c

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -825,35 +825,76 @@ static void s_client_bootstrap_on_channel_shutdown(
825825
aws_mem_release(http_bootstrap->alloc, http_bootstrap);
826826
}
827827

828-
int aws_http_client_connect_internal(
829-
const struct aws_http_client_connection_options *options,
830-
aws_http_proxy_request_transform_fn *proxy_request_transform) {
831-
832-
AWS_FATAL_ASSERT(options->proxy_options == NULL);
828+
static int s_validate_http_client_connection_options(const struct aws_http_client_connection_options *options) {
829+
if (!options) {
830+
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: http connection options are null.");
831+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
832+
}
833833

834-
struct aws_http_client_bootstrap *http_bootstrap = NULL;
835-
struct aws_string *host_name = NULL;
836-
int err = 0;
837834
struct aws_http2_connection_options http2_options = AWS_HTTP2_CONNECTION_OPTIONS_INIT;
838835
if (options->http2_options) {
839836
http2_options = *options->http2_options;
840837
}
841838

842-
if (!options || options->self_size == 0 || !options->allocator || !options->bootstrap ||
843-
options->host_name.len == 0 || !options->socket_options || !options->on_setup ||
844-
(http2_options.num_initial_settings && !http2_options.initial_settings_array)) {
839+
if (options->self_size == 0) {
840+
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Invalid connection options, self size not initialized");
841+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
842+
}
845843

846-
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Invalid options, cannot create client connection.");
847-
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
848-
goto error;
844+
if (!options->allocator) {
845+
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Invalid connection options, no allocator supplied");
846+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
847+
}
848+
849+
if (options->host_name.len == 0) {
850+
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Invalid connection options, empty host name.");
851+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
852+
}
853+
854+
if (!options->socket_options) {
855+
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Invalid connection options, socket options are null.");
856+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
857+
}
858+
859+
if (!options->on_setup) {
860+
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Invalid connection options, setup callback is null");
861+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
862+
}
863+
864+
if (http2_options.num_initial_settings && !http2_options.initial_settings_array) {
865+
AWS_LOGF_ERROR(
866+
AWS_LS_HTTP_CONNECTION,
867+
"static: Invalid connection options, h2 settings count is non-zero but settings array is null");
868+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
849869
}
850870

851871
if (options->monitoring_options && !aws_http_connection_monitoring_options_is_valid(options->monitoring_options)) {
852-
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: invalid monitoring options");
853-
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
872+
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Invalid connection options, invalid monitoring options");
873+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
874+
}
875+
876+
return AWS_OP_SUCCESS;
877+
}
878+
879+
int aws_http_client_connect_internal(
880+
const struct aws_http_client_connection_options *options,
881+
aws_http_proxy_request_transform_fn *proxy_request_transform) {
882+
883+
struct aws_http_client_bootstrap *http_bootstrap = NULL;
884+
struct aws_string *host_name = NULL;
885+
int err = 0;
886+
887+
if (s_validate_http_client_connection_options(options)) {
854888
goto error;
855889
}
856890

891+
AWS_FATAL_ASSERT(options->proxy_options == NULL);
892+
893+
struct aws_http2_connection_options http2_options = AWS_HTTP2_CONNECTION_OPTIONS_INIT;
894+
if (options->http2_options) {
895+
http2_options = *options->http2_options;
896+
}
897+
857898
/* bootstrap_new() functions requires a null-terminated c-str */
858899
host_name = aws_string_new_from_array(options->allocator, options->host_name.ptr, options->host_name.len);
859900
if (!host_name) {

0 commit comments

Comments
 (0)