Catch PackageNotFoundError during default config uri loading to prevent crash#915
Open
Nibanovic wants to merge 2 commits intoros2:rollingfrom
Open
Catch PackageNotFoundError during default config uri loading to prevent crash#915Nibanovic wants to merge 2 commits intoros2:rollingfrom
PackageNotFoundError during default config uri loading to prevent crash#915Nibanovic wants to merge 2 commits intoros2:rollingfrom
Conversation
ahcorde
approved these changes
Feb 27, 2026
Contributor
|
Pulls: #915 |
Contributor
Author
|
Build fails on missing Is this because that header in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I was using
rmw_zenoh_cpp, and I noticed my nodes kept crashing duringrclcpp::init().I was using just
librmw_zenoh_cpp.soandlibzenohc.so(some bare-bones ros2 jazzy build), not the full ament workspace.Debugging the process, it was because it couldn't locate its default config files (which are in
<ament-pkg-dir>/config/).Then
ament_index_cpp::get_package_share_directory()would throwPackageNotFoundErrorwhich was not caught.This propagates through up to
std::bad_allocfor some reason, but that is not important nowGDB Backtrace
Solution
I solved the problem by catching the error so the initialization can proceed and safely fall back to environment variables (ZENOH_SESSION_CONFIG_URI, ZENOH_ROUTER_CONFIG_URI)
Is this user-facing
I'd say it is, as it requires the user to know to set env var if using only libraries from
rmw_zenoh_cpppackage, but it is a pretty rare occurence that someone will use it in such a way.Discussion
This is a "fix" that works, but it relies on me setting the correct ENV variable. If I don't I'm not sure what owuld happen or how would zenoh sessions be configured.
The order of what happens now is:
For a fully-fledged solution, It might be good to hardcode a default
zenoh::Configinzenoh_config.hppwith these ros specific configs.Then the order of happenings would be:
Then we'd be golden in all cases.
I can do that, but I want to confirm first if that would be an acceptable direction. In any case, if this is a rare problem, we can just try-catch the ament package call, throw a warning and call it a day.
Cheers,
Nikola