From 2e5c950eb4b1eb457012fa37ff42aab4f30637c9 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Tue, 23 Aug 2022 16:00:20 -0700 Subject: [PATCH] Improve error message when create_topic fails (#405) * Improve error message when create_topic fails Signed-off-by: Shane Loretz * Grammar Signed-off-by: Shane Loretz Signed-off-by: Shane Loretz (cherry picked from commit 0898d191c14d7b84f438c445d4d92d586bd91225) --- rmw_cyclonedds_cpp/src/rmw_node.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index cc98484..c7a4cbf 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -1498,6 +1498,26 @@ static dds_entity_t create_topic(dds_entity_t pp, struct ddsi_sertopic * sertopi return tp; } +void set_error_message_from_create_topic(dds_entity_t topic) +{ + assert(topic < 0); + if (DDS_RETCODE_BAD_PARAMETER == topic) { + RMW_SET_ERROR_MSG( + "failed to create topic because the function was given" + " invalid parameters"); + } else if (DDS_RETCODE_INCONSISTENT_POLICY == topic) { + RMW_SET_ERROR_MSG( + "failed to create topic because it's already in use" + " in this context with incompatible QoS settings"); + } else if (DDS_RETCODE_PRECONDITION_NOT_MET == topic) { + RMW_SET_ERROR_MSG( + "failed to create topic because it's already in use" + " in this context with a different message type"); + } else { + RMW_SET_ERROR_MSG("failed to create topic for unknown reasons"); + } +} + ///////////////////////////////////////////////////////////////////////////////////////// /////////// /////////// /////////// PUBLICATIONS /////////// @@ -1875,7 +1895,7 @@ static CddsPublisher * create_cdds_publisher( struct ddsi_sertopic * stact; topic = create_topic(dds_ppant, sertopic, &stact); if (topic < 0) { - RMW_SET_ERROR_MSG("failed to create topic"); + set_error_message_from_create_topic(topic); goto fail_topic; } if ((qos = create_readwrite_qos(qos_policies, false)) == nullptr) { @@ -2250,7 +2270,7 @@ static CddsSubscription * create_cdds_subscription( rmw_cyclonedds_cpp::make_message_value_type(type_supports)); topic = create_topic(dds_ppant, sertopic); if (topic < 0) { - RMW_SET_ERROR_MSG("failed to create topic"); + set_error_message_from_create_topic(topic); goto fail_topic; } if ((qos = create_readwrite_qos(qos_policies, ignore_local_publications)) == nullptr) { @@ -3842,7 +3862,7 @@ static rmw_ret_t rmw_init_cs( struct ddsi_sertopic * pub_stact; pubtopic = create_topic(node->context->impl->ppant, pub_st, &pub_stact); if (pubtopic < 0) { - RMW_SET_ERROR_MSG("failed to create topic"); + set_error_message_from_create_topic(pubtopic); goto fail_pubtopic; } @@ -3851,7 +3871,7 @@ static rmw_ret_t rmw_init_cs( std::move(sub_msg_ts)); subtopic = create_topic(node->context->impl->ppant, sub_st); if (subtopic < 0) { - RMW_SET_ERROR_MSG("failed to create topic"); + set_error_message_from_create_topic(subtopic); goto fail_subtopic; } // before proceeding to outright ignore given QoS policies, sanity check them