From ded79a90cac86664d0f72b62cf4b190bccb54596 Mon Sep 17 00:00:00 2001 From: Adam Apsohian Date: Wed, 24 Jan 2024 17:16:13 -0700 Subject: [PATCH] crash on no class found Signed-off-by: Adam Aposhian --- rclcpp_components/CMakeLists.txt | 19 +++++++++++++++++++ rclcpp_components/src/node_main.cpp.in | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/rclcpp_components/CMakeLists.txt b/rclcpp_components/CMakeLists.txt index 7d4135051c..db036233d4 100644 --- a/rclcpp_components/CMakeLists.txt +++ b/rclcpp_components/CMakeLists.txt @@ -90,6 +90,25 @@ if(BUILD_TESTING) set(components "") add_library(test_component SHARED test/components/test_component.cpp) target_link_libraries(test_component PRIVATE component) + # Fake version of this macro so that rclcpp_components_register_node works + macro(_rclcpp_components_register_package_hook) + set(rclcpp_components_NODE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/src/node_main.cpp.in) + add_library(rclcpp_components::component ALIAS component) + endmacro() + include(./cmake/rclcpp_components_register_node.cmake) + rclcpp_components_register_node(test_component + PLUGIN "test_rclcpp_components::DoesNotExist" + EXECUTABLE test_component_does_not_exist_executable + ) + find_program(BASH_PROGRAM bash) + add_test( + NAME test_non_existent_plugin + # Check to make sure the executable returns a non-zero exit code + COMMAND ${BASH_PROGRAM} -c "${BASH_PROGRAM} -c \"$\"; test $? -ne 0;" + ) + set_tests_properties(test_non_existent_plugin PROPERTIES + # Need to preload this library since it doesn't get installed + ENVIRONMENT LD_PRELOAD=$) #rclcpp_components_register_nodes(test_component "test_rclcpp_components::TestComponent") set(components "${components}test_rclcpp_components::TestComponentFoo;$\n") set(components "${components}test_rclcpp_components::TestComponentBar;$\n") diff --git a/rclcpp_components/src/node_main.cpp.in b/rclcpp_components/src/node_main.cpp.in index d2a0e84601..42c856a7fc 100644 --- a/rclcpp_components/src/node_main.cpp.in +++ b/rclcpp_components/src/node_main.cpp.in @@ -62,6 +62,15 @@ int main(int argc, char * argv[]) } } + if (exec.get_all_callback_groups().empty()) { + RCLCPP_ERROR( + logger, + "Class %s not found in library %s", + class_name.c_str(), + library_name.c_str()); + return 1; + } + exec.spin(); for (auto wrapper : node_wrappers) {