@@ -317,7 +317,13 @@ void RecorderImpl::event_publisher_thread_main()
317317 auto message = rosbag2_interfaces::msg::WriteSplitEvent ();
318318 message.closed_file = bag_split_info_.closed_file ;
319319 message.opened_file = bag_split_info_.opened_file ;
320- split_event_pub_->publish (message);
320+ try {
321+ split_event_pub_->publish (message);
322+ } catch (const std::exception & e) {
323+ RCLCPP_ERROR_STREAM (
324+ node->get_logger (),
325+ " Failed to publish message on '/events/write_split' topic. \n Error: " << e.what ());
326+ }
321327 }
322328
323329 should_exit = event_publisher_thread_should_exit_;
@@ -365,8 +371,7 @@ bool RecorderImpl::is_paused()
365371void RecorderImpl::topics_discovery ()
366372{
367373 while (rclcpp::ok () && stop_discovery_ == false ) {
368- auto topics_to_subscribe =
369- get_requested_or_available_topics ();
374+ auto topics_to_subscribe = get_requested_or_available_topics ();
370375 for (const auto & topic_and_type : topics_to_subscribe) {
371376 warn_if_new_qos_for_subscribed_topic (topic_and_type.first );
372377 }
@@ -386,7 +391,13 @@ void RecorderImpl::topics_discovery()
386391std::unordered_map<std::string, std::string>
387392RecorderImpl::get_requested_or_available_topics ()
388393{
389- auto all_topics_and_types = node->get_topic_names_and_types ();
394+ std::map<std::string, std::vector<std::string>> all_topics_and_types;
395+ try {
396+ all_topics_and_types = node->get_topic_names_and_types ();
397+ } catch (const std::exception & e) {
398+ RCLCPP_ERROR_STREAM (
399+ node->get_logger (), " Failed to get topic names and types from node \n Error: " << e.what ());
400+ }
390401 return topic_filter_->filter_topics (all_topics_and_types);
391402}
392403
@@ -407,7 +418,16 @@ void RecorderImpl::subscribe_topics(
407418 const std::unordered_map<std::string, std::string> & topics_and_types)
408419{
409420 for (const auto & topic_with_type : topics_and_types) {
410- auto endpoint_infos = node->get_publishers_info_by_topic (topic_with_type.first );
421+ std::vector<rclcpp::TopicEndpointInfo> endpoint_infos;
422+ try {
423+ endpoint_infos = node->get_publishers_info_by_topic (topic_with_type.first );
424+ } catch (const std::exception & e) {
425+ RCLCPP_ERROR_STREAM (
426+ node->get_logger (), " Failed to get publishers info for '" << topic_with_type.first <<
427+ " ' topic. \n Error: " << e.what ());
428+ continue ;
429+ }
430+
411431 subscribe_topic (
412432 {
413433 topic_with_type.first ,
@@ -427,13 +447,19 @@ void RecorderImpl::subscribe_topic(const rosbag2_storage::TopicMetadata & topic)
427447 writer_->create_topic (topic);
428448
429449 Rosbag2QoS subscription_qos{subscription_qos_for_topic (topic.name )};
430- auto subscription = create_subscription (topic.name , topic.type , subscription_qos);
431- if (subscription) {
432- subscriptions_.insert ({topic.name , subscription});
433- RCLCPP_INFO_STREAM (
434- node->get_logger (),
435- " Subscribed to topic '" << topic.name << " '" );
436- } else {
450+ try {
451+ auto subscription = create_subscription (topic.name , topic.type , subscription_qos);
452+ if (subscription) {
453+ subscriptions_.insert ({topic.name , subscription});
454+ RCLCPP_INFO_STREAM (node->get_logger (), " Subscribed to topic '" << topic.name << " '" );
455+ } else {
456+ writer_->remove_topic (topic);
457+ subscriptions_.erase (topic.name );
458+ }
459+ } catch (const std::exception & e) {
460+ RCLCPP_ERROR_STREAM (
461+ node->get_logger (), " Failed to create subscription for '" << topic.name <<
462+ " ' topic. \n Error: " << e.what ());
437463 writer_->remove_topic (topic);
438464 subscriptions_.erase (topic.name );
439465 }
@@ -545,7 +571,16 @@ void RecorderImpl::warn_if_new_qos_for_subscribed_topic(const std::string & topi
545571 }
546572 const auto actual_qos = existing_subscription->second ->get_actual_qos ();
547573 const auto & used_profile = actual_qos.get_rmw_qos_profile ();
548- auto publishers_info = node->get_publishers_info_by_topic (topic_name);
574+
575+ std::vector<rclcpp::TopicEndpointInfo> publishers_info;
576+ try {
577+ publishers_info = node->get_publishers_info_by_topic (topic_name);
578+ } catch (const std::exception & e) {
579+ RCLCPP_ERROR_STREAM (
580+ node->get_logger (), " Failed to get publishers info for '" << topic_name <<
581+ " ' topic \n Error: " << e.what ());
582+ }
583+
549584 for (const auto & info : publishers_info) {
550585 auto new_profile = info.qos_profile ().get_rmw_qos_profile ();
551586 bool incompatible_reliability =
0 commit comments