Skip to main content

tsx_forge/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum ForgeError {
5    TemplateNotFound(String),
6    RenderError(String),
7    LoadError(String),
8    FrontmatterError(String),
9}
10
11impl fmt::Display for ForgeError {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        match self {
14            ForgeError::TemplateNotFound(n) => write!(f, "Template not found: {n}"),
15            ForgeError::RenderError(e) => write!(f, "Render error: {e}"),
16            ForgeError::LoadError(e) => write!(f, "Load error: {e}"),
17            ForgeError::FrontmatterError(e) => write!(f, "Frontmatter parse error: {e}"),
18        }
19    }
20}
21
22impl std::error::Error for ForgeError {}
23
24impl From<tera::Error> for ForgeError {
25    fn from(e: tera::Error) -> Self {
26        ForgeError::RenderError(e.to_string())
27    }
28}