feat(render): improve error log when variable is missing in forms
This commit is contained in:
parent
c7d6d69b72
commit
38edd67bd0
|
@ -126,21 +126,7 @@ impl<'a> Renderer for DefaultRenderer<'a> {
|
|||
if let Some(RendererError::MissingVariable(_)) =
|
||||
err.downcast_ref::<RendererError>()
|
||||
{
|
||||
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}`")]
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user