Skip to content

Commit 05a1312

Browse files
author
GueLaKais
committed
tryage to make error handling cleaner
1 parent ad65fff commit 05a1312

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

rclrs/src/node/graph.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,11 @@ mod tests {
479479
//
480480
// 99 and 98 are just chosen as arbitrary valid domain ID values. There is
481481
// otherwise nothing special about either value.
482-
let domain_id: usize = std::env::var("ROS_DOMAIN_ID")
483-
.ok()
484-
.and_then(|value| value.parse().ok())
485-
.map(|value: usize| if value != 99 { 99 } else { 98 })
486-
.unwrap_or(99);
487-
488-
let context =
489-
Context::new_with_options([], InitOptions::new().with_domain_id(Some(domain_id)))
490-
.unwrap();
482+
let domain_id = env::var("ROS_DOMAIN_ID")
483+
.map_err(|e| format!("Failed to parse ROS_DOMAIN_ID: {}", e))
484+
.and_then(|val| val.parse::<usize>().map_err(|e| format!("{}", e)))
485+
.map(|id| if id != 99 { 99 } else { 98 })
486+
.expect("Error setting domain_id");
491487
let node_name = "test_publisher_names_and_types";
492488
let node = Node::new(&context, node_name).unwrap();
493489
// Test that the graph has no publishers

0 commit comments

Comments
 (0)