From 38edd67bd088d918937b30cf240c205f7fa5ba3b Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 12 Nov 2021 21:10:04 +0100 Subject: [PATCH] feat(render): improve error log when variable is missing in forms --- espanso-render/src/renderer/mod.rs | 34 ++++++++++++++------------ espanso-render/src/renderer/resolve.rs | 7 ++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/espanso-render/src/renderer/mod.rs b/espanso-render/src/renderer/mod.rs index f90ac8a..7ed547e 100644 --- a/espanso-render/src/renderer/mod.rs +++ b/espanso-render/src/renderer/mod.rs @@ -126,21 +126,7 @@ impl<'a> Renderer for DefaultRenderer<'a> { if let Some(RendererError::MissingVariable(_)) = err.downcast_ref::() { - error!(""); - error!("TIP: This error might be happening because since version 2.1.0-alpha, Espanso changed"); - error!("the syntax to define form controls. Instead of `{{{{control}}}}` you need to use"); - error!("[[control]] (using square brackets instead of curly brackets)."); - error!(""); - error!("For example, you have a form defined like the following:"); - error!(" - trigger: test"); - error!(" form: |"); - error!(" Hi {{{{name}}}}!"); - error!(""); - error!("You'll need to replace it with:"); - error!(" - trigger: test"); - error!(" form: |"); - error!(" Hi [[name]]!"); - error!(""); + log_new_form_syntax_tip(); } } @@ -236,6 +222,24 @@ fn get_matching_template<'a>( } } +fn log_new_form_syntax_tip() { + error!(""); + error!("TIP: This error might be happening because since version 2.1.0-alpha, Espanso changed"); + error!("the syntax to define form controls. Instead of `{{{{control}}}}` you need to use"); + error!("[[control]] (using square brackets instead of curly brackets)."); + error!(""); + error!("For example, if you have a form defined like the following:"); + error!(" - trigger: test"); + error!(" form: |"); + error!(" Hi {{{{name}}}}!"); + error!(""); + error!("You'll need to replace it with:"); + error!(" - trigger: test"); + error!(" form: |"); + error!(" Hi [[name]]!"); + error!(""); +} + #[derive(Error, Debug)] pub enum RendererError { #[error("missing variable: `{0}`")] diff --git a/espanso-render/src/renderer/resolve.rs b/espanso-render/src/renderer/resolve.rs index 13ea967..c153408 100644 --- a/espanso-render/src/renderer/resolve.rs +++ b/espanso-render/src/renderer/resolve.rs @@ -23,6 +23,7 @@ use std::{ }; use anyhow::{anyhow, Result}; +use log::error; use crate::Variable; @@ -179,6 +180,12 @@ fn resolve_dependencies<'a>( resolve_dependencies(dependency_node, node_map, eval_order, resolved, seen)? } None => { + error!("could not resolve variable {:?}", dependency); + if let Some(variable) = &node.variable { + if variable.var_type == "form" { + super::log_new_form_syntax_tip(); + } + } return Err(RendererError::MissingVariable(dependency.to_string()).into()); } }