use crate::error::{ErrorCtx, TemplateError};
use crate::span::Span;
pub(crate) fn new_instance(blamed: impl Into<String>) -> TemplateError {
TemplateError::InvalidReference {
name: blamed.into(),
ctx: Box::new(ErrorCtx::default()),
}
}
pub(crate) fn new_instance_at(blamed: impl Into<String>, span: Span) -> TemplateError {
TemplateError::InvalidReference {
name: blamed.into(),
ctx: Box::new(ErrorCtx {
span,
..ErrorCtx::default()
}),
}
}
pub(crate) fn with_dot_tip(mut e: TemplateError) -> TemplateError {
if let TemplateError::InvalidReference { ctx, .. } = &mut e {
ctx.extra_tip = Some(
"It's the step after the last dot that caused this error, not those before it."
.to_string(),
);
}
e
}
pub(crate) const INVALID_REFERENCE_TIP: &str = "If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??";