ricecoder_generation/templates/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum TemplateError {
8 #[error("Template not found: {0}")]
10 NotFound(String),
11
12 #[error("Missing required placeholder: {0}")]
14 MissingPlaceholder(String),
15
16 #[error("Invalid template syntax at line {line}: {message}")]
18 InvalidSyntax {
19 line: usize,
21 message: String,
23 },
24
25 #[error("Render error: {0}")]
27 RenderError(String),
28
29 #[error("Validation failed: {0}")]
31 ValidationFailed(String),
32
33 #[error("IO error: {0}")]
35 IoError(#[from] std::io::Error),
36}
37
38impl PartialEq for TemplateError {
39 fn eq(&self, other: &Self) -> bool {
40 match (self, other) {
41 (TemplateError::NotFound(a), TemplateError::NotFound(b)) => a == b,
42 (TemplateError::MissingPlaceholder(a), TemplateError::MissingPlaceholder(b)) => a == b,
43 (
44 TemplateError::InvalidSyntax {
45 line: line_a,
46 message: msg_a,
47 },
48 TemplateError::InvalidSyntax {
49 line: line_b,
50 message: msg_b,
51 },
52 ) => line_a == line_b && msg_a == msg_b,
53 (TemplateError::RenderError(a), TemplateError::RenderError(b)) => a == b,
54 (TemplateError::ValidationFailed(a), TemplateError::ValidationFailed(b)) => a == b,
55 (TemplateError::IoError(_), TemplateError::IoError(_)) => {
56 true
58 }
59 _ => false,
60 }
61 }
62}
63
64#[derive(Debug, Error)]
66pub enum BoilerplateError {
67 #[error("Boilerplate not found: {0}")]
69 NotFound(String),
70
71 #[error("Invalid boilerplate structure: {0}")]
73 InvalidStructure(String),
74
75 #[error("File conflict at {path}: {reason}")]
77 FileConflict {
78 path: String,
80 reason: String,
82 },
83
84 #[error("Boilerplate validation failed: {0}")]
86 ValidationFailed(String),
87
88 #[error("IO error: {0}")]
90 IoError(#[from] std::io::Error),
91}
92
93impl PartialEq for BoilerplateError {
94 fn eq(&self, other: &Self) -> bool {
95 match (self, other) {
96 (BoilerplateError::NotFound(a), BoilerplateError::NotFound(b)) => a == b,
97 (BoilerplateError::InvalidStructure(a), BoilerplateError::InvalidStructure(b)) => {
98 a == b
99 }
100 (
101 BoilerplateError::FileConflict {
102 path: path_a,
103 reason: reason_a,
104 },
105 BoilerplateError::FileConflict {
106 path: path_b,
107 reason: reason_b,
108 },
109 ) => path_a == path_b && reason_a == reason_b,
110 (BoilerplateError::ValidationFailed(a), BoilerplateError::ValidationFailed(b)) => {
111 a == b
112 }
113 (BoilerplateError::IoError(_), BoilerplateError::IoError(_)) => {
114 true
116 }
117 _ => false,
118 }
119 }
120}