Skip to content

Commit 03f8832

Browse files
committed
Log error messages
1 parent 524b2b0 commit 03f8832

File tree

1 file changed

+65
-38
lines changed

1 file changed

+65
-38
lines changed

eventstream_rpc/source/EventStreamClient.cpp

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
#include <algorithm>
1515
#include <iostream>
1616

17-
/* TODO: Change to constexpr */
18-
#define EVENTSTREAM_VERSION_HEADER ":version"
19-
#define EVENTSTREAM_VERSION_STRING "0.1.0"
20-
#define CONTENT_TYPE_HEADER ":content-type"
21-
#define CONTENT_TYPE_APPLICATION_TEXT "text/plain"
22-
#define CONTENT_TYPE_APPLICATION_JSON "application/json"
23-
#define SERVICE_MODEL_TYPE_HEADER "service-model-type"
17+
constexpr auto EVENTSTREAM_VERSION_HEADER = ":version";
18+
constexpr auto EVENTSTREAM_VERSION_STRING = "0.1.0";
19+
constexpr auto CONTENT_TYPE_HEADER = ":content-type";
20+
constexpr auto CONTENT_TYPE_APPLICATION_JSON = "application/json";
21+
constexpr auto SERVICE_MODEL_TYPE_HEADER = "service-model-type";
2422

2523
namespace Aws
2624
{
@@ -320,6 +318,10 @@ namespace Aws
320318
if (crtError)
321319
{
322320
std::promise<RpcError> errorPromise;
321+
AWS_LOGF_ERROR(
322+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
323+
"A CRT error occurred while attempting to establish the connection: %s",
324+
aws_error_debug_str(crtError));
323325
errorPromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, crtError});
324326
return errorPromise.get_future();
325327
}
@@ -389,6 +391,10 @@ namespace Aws
389391

390392
if (errorCode)
391393
{
394+
AWS_LOGF_ERROR(
395+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
396+
"A CRT error occurred while attempting to send a message: %s",
397+
aws_error_debug_str(errorCode));
392398
callbackData->onFlushPromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
393399
}
394400
else
@@ -455,6 +461,10 @@ namespace Aws
455461
if (errorCode)
456462
{
457463
onFlushPromise = std::move(callbackContainer->onFlushPromise);
464+
AWS_LOGF_ERROR(
465+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
466+
"A CRT error occurred while queueing a message to be sent on the connection: %s",
467+
aws_error_debug_str(errorCode));
458468
onFlushPromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
459469
Crt::Delete(callbackContainer, connection->m_allocator);
460470
}
@@ -595,6 +605,10 @@ namespace Aws
595605
if (errorCode)
596606
{
597607
thisConnection->m_clientState = DISCONNECTED;
608+
AWS_LOGF_ERROR(
609+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
610+
"A CRT error occurred while setting up the connection: %s",
611+
aws_error_debug_str(errorCode));
598612
thisConnection->m_connectAckedPromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
599613
aws_event_stream_rpc_client_connection_release(connection);
600614
thisConnection->m_underlyingConnection = nullptr;
@@ -679,9 +693,17 @@ namespace Aws
679693
}
680694

681695
if (errorCode)
696+
{
697+
AWS_LOGF_ERROR(
698+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
699+
"A CRT error occurred while shutting down the connection: %s",
700+
aws_error_debug_str(errorCode));
682701
thisConnection->m_closedPromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
702+
}
683703
else
704+
{
684705
thisConnection->m_closedPromise.set_value({EVENT_STREAM_RPC_SUCCESS, errorCode});
706+
}
685707
}
686708

687709
void ClientConnection::s_onProtocolMessage(
@@ -999,6 +1021,10 @@ namespace Aws
9991021
if (errorCode)
10001022
{
10011023
onFlushPromise = std::move(callbackContainer->onFlushPromise);
1024+
AWS_LOGF_ERROR(
1025+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1026+
"A CRT error occurred while queueing a message to be sent on a stream: %s",
1027+
aws_error_debug_str(errorCode));
10021028
onFlushPromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
10031029
Crt::Delete(callbackContainer, m_allocator);
10041030
}
@@ -1129,40 +1155,16 @@ namespace Aws
11291155
rhs.m_rpcError = {EVENT_STREAM_RPC_UNINITIALIZED, 0};
11301156
}
11311157

1132-
TaggedResult::operator bool() const noexcept
1133-
{
1134-
if (m_responseType == OPERATION_RESPONSE)
1135-
{
1136-
return true;
1137-
}
1138-
else
1139-
{
1140-
return false;
1141-
}
1142-
}
1158+
TaggedResult::operator bool() const noexcept { return m_responseType == OPERATION_RESPONSE; }
11431159

11441160
AbstractShapeBase *TaggedResult::GetOperationResponse() const noexcept
11451161
{
1146-
if (m_responseType == OPERATION_RESPONSE)
1147-
{
1148-
return m_operationResult.m_response.get();
1149-
}
1150-
else
1151-
{
1152-
return nullptr;
1153-
}
1162+
return (m_responseType == OPERATION_RESPONSE) ? m_operationResult.m_response.get() : nullptr;
11541163
}
11551164

11561165
OperationError *TaggedResult::GetOperationError() const noexcept
11571166
{
1158-
if (m_responseType == OPERATION_ERROR)
1159-
{
1160-
return m_operationResult.m_error.get();
1161-
}
1162-
else
1163-
{
1164-
return nullptr;
1165-
}
1167+
return (m_responseType == OPERATION_ERROR) ? m_operationResult.m_error.get() : nullptr;
11661168
}
11671169

11681170
RpcError TaggedResult::GetRpcError() const noexcept
@@ -1185,6 +1187,7 @@ namespace Aws
11851187

11861188
if (m_clientContinuation.IsClosed() && !m_resultReceived)
11871189
{
1190+
AWS_LOGF_ERROR(AWS_LS_EVENT_STREAM_RPC_CLIENT, "The underlying stream is already closed.");
11881191
m_initialResponsePromise.set_value(TaggedResult({EVENT_STREAM_RPC_CONNECTION_CLOSED, 0}));
11891192
m_resultReceived = true;
11901193
}
@@ -1230,7 +1233,7 @@ namespace Aws
12301233

12311234
if (response.get() == nullptr)
12321235
{
1233-
/* TODO: Log an error */
1236+
AWS_LOGF_ERROR(AWS_LS_EVENT_STREAM_RPC_CLIENT, "Failed to allocate a response from the payload.");
12341237
return EVENT_STREAM_RPC_ALLOCATION_ERROR;
12351238
}
12361239

@@ -1301,7 +1304,7 @@ namespace Aws
13011304
{
13021305
(void)operationError;
13031306
(void)rpcError;
1304-
/* Always returning true forces the stream to close when an error occurs. */
1307+
/* Note: Always returning true forces the stream to close when an error occurs. */
13051308
return true;
13061309
}
13071310

@@ -1333,6 +1336,10 @@ namespace Aws
13331336
if (modelHeader == nullptr)
13341337
{
13351338
/* Missing required service model type header. */
1339+
AWS_LOGF_ERROR(
1340+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1341+
"A required header (%s) could not be found in the message.",
1342+
SERVICE_MODEL_TYPE_HEADER);
13361343
errorCode = EVENT_STREAM_RPC_UNMAPPED_DATA;
13371344
}
13381345

@@ -1344,12 +1351,18 @@ namespace Aws
13441351
{
13451352
if (m_messageCount == 1 && m_operationModelContext.GetInitialResponseModelName() != modelName)
13461353
{
1354+
AWS_LOGF_ERROR(
1355+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1356+
"The model name of the initial response did not match its expected model name.");
13471357
errorCode = EVENT_STREAM_RPC_UNMAPPED_DATA;
13481358
}
13491359
else if (
13501360
m_messageCount > 1 && m_operationModelContext.GetStreamingResponseModelName().has_value() &&
13511361
m_operationModelContext.GetStreamingResponseModelName().value() != modelName)
13521362
{
1363+
AWS_LOGF_ERROR(
1364+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1365+
"The model name of a subsequent response did not match its expected model name.");
13531366
errorCode = EVENT_STREAM_RPC_UNMAPPED_DATA;
13541367
}
13551368
}
@@ -1361,12 +1374,21 @@ namespace Aws
13611374
contentHeader = GetHeaderByName(headers, Crt::String(CONTENT_TYPE_HEADER));
13621375
if (contentHeader == nullptr)
13631376
{
1364-
/* TODO: Log an error. */
13651377
/* Missing required content type header. */
1366-
errorCode = EVENT_STREAM_RPC_UNMAPPED_DATA;
1378+
AWS_LOGF_ERROR(
1379+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1380+
"A required header (%s) could not be found in the message.",
1381+
CONTENT_TYPE_HEADER);
1382+
errorCode = EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE;
13671383
}
13681384
else if (contentHeader->GetValueAsString(contentType) && contentType != CONTENT_TYPE_APPLICATION_JSON)
13691385
{
1386+
/* Missing required content type header. */
1387+
AWS_LOGF_ERROR(
1388+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1389+
"The content type (%s) header was specified with an unsupported value (%s).",
1390+
CONTENT_TYPE_HEADER,
1391+
contentType.c_str());
13701392
errorCode = EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE;
13711393
}
13721394
}
@@ -1498,6 +1520,11 @@ namespace Aws
14981520
if (errorCode)
14991521
{
15001522
onTerminatePromise = std::move(callbackContainer->onFlushPromise);
1523+
std::promise<RpcError> errorPromise;
1524+
AWS_LOGF_ERROR(
1525+
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1526+
"A CRT error occurred while closing the stream: %s",
1527+
aws_error_debug_str(errorCode));
15011528
onTerminatePromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
15021529
Crt::Delete(callbackContainer, m_allocator);
15031530
}

0 commit comments

Comments
 (0)