From c3b958e42b6d361a018e82da3dfb3f20f70a369a Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Tue, 15 Dec 2020 19:16:32 -0300 Subject: [PATCH] Handle typesupport errors on fetch. (#495) * Handle typesupport errors on fetch. Signed-off-by: Michel Hidalgo --- rmw_fastrtps_cpp/src/publisher.cpp | 12 +++++++++++- rmw_fastrtps_cpp/src/rmw_client.cpp | 12 +++++++++++- rmw_fastrtps_cpp/src/rmw_service.cpp | 12 +++++++++++- rmw_fastrtps_cpp/src/subscription.cpp | 12 +++++++++++- rmw_fastrtps_dynamic_cpp/src/publisher.cpp | 13 ++++++++++++- rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp | 11 ++++++++++- rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp | 12 +++++++++++- rmw_fastrtps_dynamic_cpp/src/subscription.cpp | 13 ++++++++++++- 8 files changed, 89 insertions(+), 8 deletions(-) diff --git a/rmw_fastrtps_cpp/src/publisher.cpp b/rmw_fastrtps_cpp/src/publisher.cpp index 06032e240..9cb259a26 100644 --- a/rmw_fastrtps_cpp/src/publisher.cpp +++ b/rmw_fastrtps_cpp/src/publisher.cpp @@ -18,6 +18,7 @@ #include "fastrtps/Domain.h" #include "fastrtps/participant/Participant.h" +#include "rcutils/error_handling.h" #include "rcutils/macros.h" #include "rmw/allocators.h" @@ -84,10 +85,19 @@ rmw_fastrtps_cpp::create_publisher( const rosidl_message_type_support_t * type_support = get_message_typesupport_handle( type_supports, RMW_FASTRTPS_CPP_TYPESUPPORT_C); if (!type_support) { + rcutils_error_string_t prev_error_string = rcutils_get_error_string(); + rcutils_reset_error(); type_support = get_message_typesupport_handle( type_supports, RMW_FASTRTPS_CPP_TYPESUPPORT_CPP); if (!type_support) { - RMW_SET_ERROR_MSG("type support not from this implementation"); + rcutils_error_string_t error_string = rcutils_get_error_string(); + rcutils_reset_error(); + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Type support not from this implementation. Got:\n" + " %s\n" + " %s\n" + "while fetching it", + prev_error_string.str, error_string.str); return nullptr; } } diff --git a/rmw_fastrtps_cpp/src/rmw_client.cpp b/rmw_fastrtps_cpp/src/rmw_client.cpp index 642c829da..356f3afc6 100644 --- a/rmw_fastrtps_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_cpp/src/rmw_client.cpp @@ -15,6 +15,7 @@ #include #include "rcpputils/scope_exit.hpp" +#include "rcutils/error_handling.h" #include "rcutils/logging_macros.h" #include "rmw/allocators.h" @@ -81,10 +82,19 @@ rmw_create_client( const rosidl_service_type_support_t * type_support = get_service_typesupport_handle( type_supports, RMW_FASTRTPS_CPP_TYPESUPPORT_C); if (!type_support) { + rcutils_error_string_t prev_error_string = rcutils_get_error_string(); + rcutils_reset_error(); type_support = get_service_typesupport_handle( type_supports, RMW_FASTRTPS_CPP_TYPESUPPORT_CPP); if (!type_support) { - RMW_SET_ERROR_MSG("type support not from this implementation"); + rcutils_error_string_t error_string = rcutils_get_error_string(); + rcutils_reset_error(); + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Type support not from this implementation. Got:\n" + " %s\n" + " %s\n" + "while fetching it", + prev_error_string.str, error_string.str); return nullptr; } } diff --git a/rmw_fastrtps_cpp/src/rmw_service.cpp b/rmw_fastrtps_cpp/src/rmw_service.cpp index ee066e709..d5eb1d290 100644 --- a/rmw_fastrtps_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service.cpp @@ -26,6 +26,7 @@ #include #include "rcpputils/scope_exit.hpp" +#include "rcutils/error_handling.h" #include "rcutils/logging_macros.h" #include "rmw/allocators.h" @@ -93,10 +94,19 @@ rmw_create_service( const rosidl_service_type_support_t * type_support = get_service_typesupport_handle( type_supports, RMW_FASTRTPS_CPP_TYPESUPPORT_C); if (!type_support) { + rcutils_error_string_t prev_error_string = rcutils_get_error_string(); + rcutils_reset_error(); type_support = get_service_typesupport_handle( type_supports, RMW_FASTRTPS_CPP_TYPESUPPORT_CPP); if (!type_support) { - RMW_SET_ERROR_MSG("type support not from this implementation"); + rcutils_error_string_t error_string = rcutils_get_error_string(); + rcutils_reset_error(); + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Type support not from this implementation. Got:\n" + " %s\n" + " %s\n" + "while fetching it", + prev_error_string.str, error_string.str); return nullptr; } } diff --git a/rmw_fastrtps_cpp/src/subscription.cpp b/rmw_fastrtps_cpp/src/subscription.cpp index 6259bb5b8..7f7ed9c49 100644 --- a/rmw_fastrtps_cpp/src/subscription.cpp +++ b/rmw_fastrtps_cpp/src/subscription.cpp @@ -16,6 +16,7 @@ #include #include "rcutils/allocator.h" +#include "rcutils/error_handling.h" #include "rcutils/macros.h" #include "rcutils/strdup.h" @@ -88,10 +89,19 @@ create_subscription( const rosidl_message_type_support_t * type_support = get_message_typesupport_handle( type_supports, RMW_FASTRTPS_CPP_TYPESUPPORT_C); if (!type_support) { + rcutils_error_string_t prev_error_string = rcutils_get_error_string(); + rcutils_reset_error(); type_support = get_message_typesupport_handle( type_supports, RMW_FASTRTPS_CPP_TYPESUPPORT_CPP); if (!type_support) { - RMW_SET_ERROR_MSG("type support not from this implementation"); + rcutils_error_string_t error_string = rcutils_get_error_string(); + rcutils_reset_error(); + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Type support not from this implementation. Got:\n" + " %s\n" + " %s\n" + "while fetching it", + prev_error_string.str, error_string.str); return nullptr; } } diff --git a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp index 3e067b1a2..74327cad6 100644 --- a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp @@ -15,6 +15,8 @@ #include +#include "rcutils/error_handling.h" + #include "rmw/allocators.h" #include "rmw/error_handling.h" #include "rmw/rmw.h" @@ -82,10 +84,19 @@ rmw_fastrtps_dynamic_cpp::create_publisher( const rosidl_message_type_support_t * type_support = get_message_typesupport_handle( type_supports, rosidl_typesupport_introspection_c__identifier); if (!type_support) { + rcutils_error_string_t prev_error_string = rcutils_get_error_string(); + rcutils_reset_error(); type_support = get_message_typesupport_handle( type_supports, rosidl_typesupport_introspection_cpp::typesupport_identifier); if (!type_support) { - RMW_SET_ERROR_MSG("type support not from this implementation"); + rcutils_error_string_t error_string = rcutils_get_error_string(); + rcutils_reset_error(); + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Type support not from this implementation. Got:\n" + " %s\n" + " %s\n" + "while fetching it", + prev_error_string.str, error_string.str); return nullptr; } } diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp index e7f24a769..ed9572504 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp @@ -97,10 +97,19 @@ rmw_create_client( const rosidl_service_type_support_t * type_support = get_service_typesupport_handle( type_supports, rosidl_typesupport_introspection_c__identifier); if (!type_support) { + rcutils_error_string_t prev_error_string = rcutils_get_error_string(); + rcutils_reset_error(); type_support = get_service_typesupport_handle( type_supports, rosidl_typesupport_introspection_cpp::typesupport_identifier); if (!type_support) { - RMW_SET_ERROR_MSG("type support not from this implementation"); + rcutils_error_string_t error_string = rcutils_get_error_string(); + rcutils_reset_error(); + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Type support not from this implementation. Got:\n" + " %s\n" + " %s\n" + "while fetching it", + prev_error_string.str, error_string.str); return nullptr; } } diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp index 11e06a343..ff948533b 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp @@ -25,6 +25,7 @@ #include #include +#include "rcutils/error_handling.h" #include "rcutils/logging_macros.h" #include "rmw/allocators.h" @@ -108,10 +109,19 @@ rmw_create_service( const rosidl_service_type_support_t * type_support = get_service_typesupport_handle( type_supports, rosidl_typesupport_introspection_c__identifier); if (!type_support) { + rcutils_error_string_t prev_error_string = rcutils_get_error_string(); + rcutils_reset_error(); type_support = get_service_typesupport_handle( type_supports, rosidl_typesupport_introspection_cpp::typesupport_identifier); if (!type_support) { - RMW_SET_ERROR_MSG("type support not from this implementation"); + rcutils_error_string_t error_string = rcutils_get_error_string(); + rcutils_reset_error(); + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Type support not from this implementation. Got:\n" + " %s\n" + " %s\n" + "while fetching it", + prev_error_string.str, error_string.str); return nullptr; } } diff --git a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp index b68662bac..1a716294f 100644 --- a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp @@ -15,6 +15,8 @@ #include #include +#include "rcutils/error_handling.h" + #include "rmw/allocators.h" #include "rmw/error_handling.h" #include "rmw/rmw.h" @@ -88,10 +90,19 @@ create_subscription( const rosidl_message_type_support_t * type_support = get_message_typesupport_handle( type_supports, rosidl_typesupport_introspection_c__identifier); if (!type_support) { + rcutils_error_string_t prev_error_string = rcutils_get_error_string(); + rcutils_reset_error(); type_support = get_message_typesupport_handle( type_supports, rosidl_typesupport_introspection_cpp::typesupport_identifier); if (!type_support) { - RMW_SET_ERROR_MSG("type support not from this implementation"); + rcutils_error_string_t error_string = rcutils_get_error_string(); + rcutils_reset_error(); + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Type support not from this implementation. Got:\n" + " %s\n" + " %s\n" + "while fetching it", + prev_error_string.str, error_string.str); return nullptr; } }