use crate::error::error_ctx::render_ftl_stack_section;
use crate::error::{ErrorCtx, TemplateError};
pub(crate) fn with_stack(
mut e: TemplateError,
stack: Vec<crate::error::StackFrame>,
) -> TemplateError {
let section = render_ftl_stack_section(&stack);
let Some(section) = section else {
return e;
};
match &mut e {
TemplateError::InvalidReference { ctx, .. } | TemplateError::TypeMismatch { ctx, .. } => {
if ctx.instruction_stack.is_empty() {
ctx.instruction_stack = stack;
}
}
TemplateError::Misc { message }
| TemplateError::Parse { message, .. }
| TemplateError::Model { message } => {
if !message.contains("FTL stack trace") {
message.push_str(§ion);
}
}
TemplateError::Stop { message } => {
let msg = message.get_or_insert_with(String::new);
if !msg.contains("FTL stack trace") {
if msg.is_empty() {
msg.push_str("[No error description was available.]");
}
msg.push_str(§ion);
}
}
TemplateError::NotFound { .. } => {}
TemplateError::Flow(_) | TemplateError::Io(_) => {}
}
e
}
#[allow(unused_imports)]
use ErrorCtx as _ErrorDescriptionBuilderAnchor;