Merge pull request #422 from ros2/mergify/bp/foxy/pr-410

Adds topic name to error msg when create_topic fails (backport #410)
This commit is contained in:
Tully Foote 2022-09-16 13:40:08 -07:00 committed by GitHub
commit 440b191ae6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1498,23 +1498,24 @@ static dds_entity_t create_topic(dds_entity_t pp, struct ddsi_sertopic * sertopi
return tp; return tp;
} }
void set_error_message_from_create_topic(dds_entity_t topic) void set_error_message_from_create_topic(dds_entity_t topic, const std::string & topic_name)
{ {
assert(topic < 0); assert(topic < 0);
if (DDS_RETCODE_BAD_PARAMETER == topic) { if (DDS_RETCODE_BAD_PARAMETER == topic) {
RMW_SET_ERROR_MSG( const std::string error_msg = "failed to create topic [" + topic_name +
"failed to create topic because the function was given" "] because the function was given invalid parameters";
" invalid parameters"); RMW_SET_ERROR_MSG(error_msg.c_str());
} else if (DDS_RETCODE_INCONSISTENT_POLICY == topic) { } else if (DDS_RETCODE_INCONSISTENT_POLICY == topic) {
RMW_SET_ERROR_MSG( const std::string error_msg = "failed to create topic [" + topic_name +
"failed to create topic because it's already in use" "] because it's already in use in this context with incompatible QoS settings";
" in this context with incompatible QoS settings"); RMW_SET_ERROR_MSG(error_msg.c_str());
} else if (DDS_RETCODE_PRECONDITION_NOT_MET == topic) { } else if (DDS_RETCODE_PRECONDITION_NOT_MET == topic) {
RMW_SET_ERROR_MSG( const std::string error_msg = "failed to create topic [" + topic_name +
"failed to create topic because it's already in use" "] because it's already in use in this context with a different message type";
" in this context with a different message type"); RMW_SET_ERROR_MSG(error_msg.c_str());
} else { } else {
RMW_SET_ERROR_MSG("failed to create topic for unknown reasons"); const std::string error_msg = "failed to create topic [" + topic_name + "] for unknown reasons";
RMW_SET_ERROR_MSG(error_msg.c_str());
} }
} }
@ -1895,7 +1896,7 @@ static CddsPublisher * create_cdds_publisher(
struct ddsi_sertopic * stact; struct ddsi_sertopic * stact;
topic = create_topic(dds_ppant, sertopic, &stact); topic = create_topic(dds_ppant, sertopic, &stact);
if (topic < 0) { if (topic < 0) {
set_error_message_from_create_topic(topic); set_error_message_from_create_topic(topic, fqtopic_name);
goto fail_topic; goto fail_topic;
} }
if ((qos = create_readwrite_qos(qos_policies, false)) == nullptr) { if ((qos = create_readwrite_qos(qos_policies, false)) == nullptr) {
@ -2270,7 +2271,7 @@ static CddsSubscription * create_cdds_subscription(
rmw_cyclonedds_cpp::make_message_value_type(type_supports)); rmw_cyclonedds_cpp::make_message_value_type(type_supports));
topic = create_topic(dds_ppant, sertopic); topic = create_topic(dds_ppant, sertopic);
if (topic < 0) { if (topic < 0) {
set_error_message_from_create_topic(topic); set_error_message_from_create_topic(topic, fqtopic_name);
goto fail_topic; goto fail_topic;
} }
if ((qos = create_readwrite_qos(qos_policies, ignore_local_publications)) == nullptr) { if ((qos = create_readwrite_qos(qos_policies, ignore_local_publications)) == nullptr) {
@ -3862,7 +3863,7 @@ static rmw_ret_t rmw_init_cs(
struct ddsi_sertopic * pub_stact; struct ddsi_sertopic * pub_stact;
pubtopic = create_topic(node->context->impl->ppant, pub_st, &pub_stact); pubtopic = create_topic(node->context->impl->ppant, pub_st, &pub_stact);
if (pubtopic < 0) { if (pubtopic < 0) {
set_error_message_from_create_topic(pubtopic); set_error_message_from_create_topic(pubtopic, pubtopic_name);
goto fail_pubtopic; goto fail_pubtopic;
} }
@ -3871,7 +3872,7 @@ static rmw_ret_t rmw_init_cs(
std::move(sub_msg_ts)); std::move(sub_msg_ts));
subtopic = create_topic(node->context->impl->ppant, sub_st); subtopic = create_topic(node->context->impl->ppant, sub_st);
if (subtopic < 0) { if (subtopic < 0) {
set_error_message_from_create_topic(subtopic); set_error_message_from_create_topic(subtopic, subtopic_name);
goto fail_subtopic; goto fail_subtopic;
} }
// before proceeding to outright ignore given QoS policies, sanity check them // before proceeding to outright ignore given QoS policies, sanity check them