From ac9f3a2a9d5d4602890e78df53d9903883563556 Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Wed, 8 Jan 2025 13:23:01 -0800 Subject: [PATCH 1/2] Check reason string in MQTT5 samples --- samples/mqtt5/mqtt5_pubsub/main.cpp | 22 +++++++++---------- .../mqtt5/mqtt5_shared_subscription/main.cpp | 21 ++++++++++-------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/samples/mqtt5/mqtt5_pubsub/main.cpp b/samples/mqtt5/mqtt5_pubsub/main.cpp index 479146c5a..34c348bbd 100644 --- a/samples/mqtt5/mqtt5_pubsub/main.cpp +++ b/samples/mqtt5/mqtt5_pubsub/main.cpp @@ -141,11 +141,11 @@ int main(int argc, char *argv[]) { if (reasonCode > Mqtt5::SubAckReasonCode::AWS_MQTT5_SARC_UNSPECIFIED_ERROR) { - fprintf( - stdout, - "MQTT5 Client Subscription failed with server error code: (%d)%s\n", - reasonCode, - suback->getReasonString()->c_str()); + fprintf(stdout, "MQTT5 Client Subscription failed with server error code %d\n", reasonCode); + if (suback->getReasonString().has_value()) + { + fprintf(stdout, "\tError reason string: %s\n", suback->getReasonString()->c_str()); + } subscribeSuccess.set_value(false); return; } @@ -185,13 +185,13 @@ int main(int argc, char *argv[]) } else { - fprintf( - stdout, - "PubACK reason code: %d : %s\n", - puback->getReasonCode(), - puback->getReasonString()->c_str()); + fprintf(stdout, "PubACK reason code: %d\n", puback->getReasonCode()); + if (puback->getReasonString().has_value()) + { + fprintf(stdout, "\nError reason string: %s\n", puback->getReasonString()->c_str()); + } } - }; + } }; uint32_t publishedCount = 0; diff --git a/samples/mqtt5/mqtt5_shared_subscription/main.cpp b/samples/mqtt5/mqtt5_shared_subscription/main.cpp index 6f8085699..bc92cee01 100644 --- a/samples/mqtt5/mqtt5_shared_subscription/main.cpp +++ b/samples/mqtt5/mqtt5_shared_subscription/main.cpp @@ -246,11 +246,11 @@ int main(int argc, char *argv[]) { if (reasonCode >= Mqtt5::SubAckReasonCode::AWS_MQTT5_SARC_UNSPECIFIED_ERROR) { - fprintf( - stdout, - "MQTT5 Client Subscription failed with server error code: (%d)%s\n", - reasonCode, - suback->getReasonString()->c_str()); + fprintf(stdout, "MQTT5 Client Subscription failed with server error code: (%d)\n", reasonCode); + if (suback->getReasonString().has_value()) + { + fprintf(stdout, "\tError reason string: %s\n", suback->getReasonString()->c_str()); + } subscribeSuccess.set_value(reasonCode); return; } @@ -331,12 +331,15 @@ int main(int argc, char *argv[]) { fprintf( stdout, - "[%s] Publish failed. PubACK reason code: %d : %s\n", + "[%s] Publish failed. PubACK reason code: %d\n", publisher->name.c_str(), - puback->getReasonCode(), - puback->getReasonString()->c_str()); + puback->getReasonCode()); + if (puback->getReasonString().has_value()) + { + fprintf(stdout, "\nError reason string: %s\n", puback->getReasonString()->c_str()); + } } - }; + } }; uint64_t publishedCount = 0; From 82db504815edc6843a7f3064aec02acc2d2a8172 Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Wed, 8 Jan 2025 13:29:40 -0800 Subject: [PATCH 2/2] Make print messages similar --- samples/mqtt5/mqtt5_pubsub/main.cpp | 2 +- samples/mqtt5/mqtt5_shared_subscription/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/mqtt5/mqtt5_pubsub/main.cpp b/samples/mqtt5/mqtt5_pubsub/main.cpp index 34c348bbd..070797c60 100644 --- a/samples/mqtt5/mqtt5_pubsub/main.cpp +++ b/samples/mqtt5/mqtt5_pubsub/main.cpp @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) { if (reasonCode > Mqtt5::SubAckReasonCode::AWS_MQTT5_SARC_UNSPECIFIED_ERROR) { - fprintf(stdout, "MQTT5 Client Subscription failed with server error code %d\n", reasonCode); + fprintf(stdout, "MQTT5 Client Subscription failed with server error code: %d\n", reasonCode); if (suback->getReasonString().has_value()) { fprintf(stdout, "\tError reason string: %s\n", suback->getReasonString()->c_str()); diff --git a/samples/mqtt5/mqtt5_shared_subscription/main.cpp b/samples/mqtt5/mqtt5_shared_subscription/main.cpp index bc92cee01..88a2c9fd2 100644 --- a/samples/mqtt5/mqtt5_shared_subscription/main.cpp +++ b/samples/mqtt5/mqtt5_shared_subscription/main.cpp @@ -246,7 +246,7 @@ int main(int argc, char *argv[]) { if (reasonCode >= Mqtt5::SubAckReasonCode::AWS_MQTT5_SARC_UNSPECIFIED_ERROR) { - fprintf(stdout, "MQTT5 Client Subscription failed with server error code: (%d)\n", reasonCode); + fprintf(stdout, "MQTT5 Client Subscription failed with server error code: %d\n", reasonCode); if (suback->getReasonString().has_value()) { fprintf(stdout, "\tError reason string: %s\n", suback->getReasonString()->c_str());