1use crate::error::{HelperError, IoError};
3use std::fmt;
4use thiserror::Error;
5
6#[derive(Error)]
8pub enum RenderError {
9 #[error("Partial '{0}' not found")]
11 PartialNotFound(String),
12
13 #[error("Variable '{0}' not found in {1}, check the variable path and verify the template data")]
15 VariableNotFound(String, String),
16
17 #[error("Helper '{0}' not found, check the name")]
19 HelperNotFound(String),
20
21 #[error("Syntax error while evaluating path '{0}'")]
27 EvaluatePath(String),
28
29 #[error("Cycle detected whilst processing partial '{0}'")]
31 PartialCycle(String),
32
33 #[error("Cycle detected whilst processing helper '{0}'")]
35 HelperCycle(String),
36
37 #[error("Partial names must be simple identifiers, got path '{0}'")]
39 PartialIdentifier(String),
40 #[error("Block names must be simple identifiers, got path '{0}'")]
42 BlockIdentifier(String),
43 #[error("Block target sub expressions are only supported for partials")]
45 BlockTargetSubExpr,
46
47 #[error(transparent)]
49 Helper(#[from] HelperError),
50
51 #[error(transparent)]
57 Io(#[from] IoError),
58
59 #[error(transparent)]
61 Json(#[from] serde_json::Error),
62}
63
64impl fmt::Debug for RenderError {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 write!(f, "{}", self.to_string())
67 }
69}
70
71impl From<std::io::Error> for RenderError {
72 fn from(err: std::io::Error) -> Self {
73 Self::Io(IoError::Io(err))
74 }
75}
76
77impl PartialEq for RenderError {
78 fn eq(&self, other: &Self) -> bool {
79 match (self, other) {
80 (Self::PartialNotFound(ref s), Self::PartialNotFound(ref o)) => {
81 s == o
82 }
83 _ => false,
84 }
85 }
86}
87
88impl Eq for RenderError {}