Skip to content

Commit

Permalink
templater: don't panic on PropertyPlaceholder unset error
Browse files Browse the repository at this point in the history
The idea is that, if .extract() succeeded in static context, it means the
property can be evaluated as constant. This will potentially eliminate
expect_string_literal_with(), though I'm not too sure if it's a good idea.
If needed, maybe we can extend the idea to suppress type/name resolution errors
by "if(some_static_config_knob, x, y)".
  • Loading branch information
yuja committed Mar 29, 2024
1 parent 32b623d commit f83d1a8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cli/src/templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,11 @@ impl<O: Clone> TemplateProperty for PropertyPlaceholder<O> {
type Output = O;

fn extract(&self) -> Result<Self::Output, TemplatePropertyError> {
Ok(self
.value
.borrow()
.as_ref()
.expect("placeholder value must be set before evaluating template")
.clone())
if let Some(value) = self.value.borrow().as_ref() {
Ok(value.clone())
} else {
Err(TemplatePropertyError("Placeholder value is not set".into()))
}
}
}

Expand Down

0 comments on commit f83d1a8

Please sign in to comment.