templater: don't panic on PropertyPlaceholder unset error

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)".
This commit is contained in:
Yuya Nishihara 2024-03-21 00:40:02 +09:00
parent 32b623db67
commit f83d1a840e

View file

@ -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()))
}
}
}