Skip to content

Commit

Permalink
fix panic when arguments evaluated eagerly
Browse files Browse the repository at this point in the history
  • Loading branch information
adwk67 committed Dec 19, 2024
1 parent 8af0471 commit 8af2e01
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rust/stackablectl/src/cmds/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ async fn describe_cmd(
.add_row(vec!["DESCRIPTION", &demo.description])
.add_row_if(
|_, _| demo.documentation.is_some(),
vec!["DOCUMENTATION", demo.documentation.as_ref().unwrap()],
// The simple unwrap() may be called despite the condition, if add_row_if evaluates its arguments eagerly, so make sure to avoid a panic
demo.documentation
.as_ref()
.map(|doc| vec!["DOCUMENTATION", doc])
.unwrap_or_else(Vec::new),
)
.add_row(vec!["STACK", &demo.stack])
.add_row(vec!["LABELS", &demo.labels.join(", ")]);
Expand Down

0 comments on commit 8af2e01

Please sign in to comment.