From a9dae58fc1847ec46795bfea8a0e606e7a3bbbc1 Mon Sep 17 00:00:00 2001 From: nibanovic Date: Fri, 27 Feb 2026 16:29:38 +0100 Subject: [PATCH 1/2] catch get_package_share_path() throw on config load --- rmw_zenoh_cpp/src/detail/zenoh_config.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/zenoh_config.cpp b/rmw_zenoh_cpp/src/detail/zenoh_config.cpp index 80ac4faf..0a763ffd 100644 --- a/rmw_zenoh_cpp/src/detail/zenoh_config.cpp +++ b/rmw_zenoh_cpp/src/detail/zenoh_config.cpp @@ -26,6 +26,7 @@ #include "logging_macros.hpp" #include +#include /* for PackageNotFoundError */ #include ///============================================================================= @@ -119,12 +120,21 @@ std::optional get_z_config(const ConfigurableEntity & entity) "rmw_zenoh_cpp", "get_z_config called with invalid ConfigurableEntity."); return std::nullopt; } - // Get the absolute path to the default configuration file. - std::filesystem::path path_to_config_folder = - ament_index_cpp::get_package_share_path("rmw_zenoh_cpp") / "config"; - - const std::filesystem::path default_config_path = - path_to_config_folder / envar_map_it->second.second; + + std::filesystem::path default_config_path; + + try { + // Get the absolute path to the default configuration file. + std::filesystem::path path_to_config_folder = + ament_index_cpp::get_package_share_path("rmw_zenoh_cpp") / "config"; + + default_config_path = path_to_config_folder / envar_map_it->second.second; + } catch (const ament_index_cpp::PackageNotFoundError& e) { + RMW_ZENOH_LOG_WARN_NAMED( + "rmw_zenoh_cpp", + "Failed to find rmw_zenoh_cpp package in ament_index (%s). " + "Relying on 'ZENOH_*_CONFIG_URI' ENV vars.", e.what()); + } return _get_z_config(envar_map_it->second.first, default_config_path); } From 7e4186e7e33efa96bea12ada99120d04ae32464c Mon Sep 17 00:00:00 2001 From: nibanovic Date: Fri, 27 Feb 2026 17:14:23 +0100 Subject: [PATCH 2/2] ament uncrustify --- rmw_zenoh_cpp/src/detail/zenoh_config.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/zenoh_config.cpp b/rmw_zenoh_cpp/src/detail/zenoh_config.cpp index 0a763ffd..796706ab 100644 --- a/rmw_zenoh_cpp/src/detail/zenoh_config.cpp +++ b/rmw_zenoh_cpp/src/detail/zenoh_config.cpp @@ -120,7 +120,7 @@ std::optional get_z_config(const ConfigurableEntity & entity) "rmw_zenoh_cpp", "get_z_config called with invalid ConfigurableEntity."); return std::nullopt; } - + std::filesystem::path default_config_path; try { @@ -129,9 +129,9 @@ std::optional get_z_config(const ConfigurableEntity & entity) ament_index_cpp::get_package_share_path("rmw_zenoh_cpp") / "config"; default_config_path = path_to_config_folder / envar_map_it->second.second; - } catch (const ament_index_cpp::PackageNotFoundError& e) { + } catch (const ament_index_cpp::PackageNotFoundError & e) { RMW_ZENOH_LOG_WARN_NAMED( - "rmw_zenoh_cpp", + "rmw_zenoh_cpp", "Failed to find rmw_zenoh_cpp package in ament_index (%s). " "Relying on 'ZENOH_*_CONFIG_URI' ENV vars.", e.what()); }