From f83d1a840e0a9b23737c31191ca46d6277cf9569 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 21 Mar 2024 00:40:02 +0900 Subject: [PATCH] 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)". --- cli/src/templater.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cli/src/templater.rs b/cli/src/templater.rs index 4aa2f9291..c588d0bf8 100644 --- a/cli/src/templater.rs +++ b/cli/src/templater.rs @@ -620,12 +620,11 @@ impl TemplateProperty for PropertyPlaceholder { type Output = O; fn extract(&self) -> Result { - 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())) + } } }