[r2r_common] Do not panic in get_wanted_messages() if AMENT_PREFIX_PATH is not set

This commit is contained in:
aeon 2022-11-25 04:07:51 +08:00
parent 55cce8caec
commit 801d09d136
1 changed files with 9 additions and 6 deletions

View File

@ -148,13 +148,16 @@ pub fn get_wanted_messages() -> Vec<RosMsg> {
get_ros_msgs_files(&dirs)
} else {
// Else we look for all msgs we can find using the ament prefix path.
let ament_prefix_var = env::var("AMENT_PREFIX_PATH").expect("Source your ROS!");
if let Ok(ament_prefix_var) = env::var("AMENT_PREFIX_PATH") {
let paths = ament_prefix_var
.split(':')
.map(Path::new)
.collect::<Vec<_>>();
get_ros_msgs(&paths)
} else {
vec![]
}
};
let msgs = parse_msgs(&msgs);