1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum EngineError {
6 #[error("Template not found: {name}")]
7 TemplateNotFound { name: String },
8
9 #[error("Invalid template configuration: {reason}")]
10 InvalidConfig { reason: String },
11
12 #[error("File operation failed: {path}")]
13 FileError {
14 path: PathBuf,
15 #[source]
16 source: std::io::Error,
17 },
18
19 #[error("Template processing failed: {0}")]
20 ProcessingError(#[from] tera::Error),
21
22 #[error("YAML parsing failed: {0}")]
23 YamlError(#[from] serde_yaml::Error),
24
25 #[error("Variable validation failed: {variable}: {reason}")]
26 VariableError { variable: String, reason: String },
27
28 #[error("Feature dependency not met: {feature} requires {dependency}")]
29 FeatureDependencyError { feature: String, dependency: String },
30
31 #[error("Template composition failed: {reason}")]
32 CompositionError { reason: String },
33}
34
35pub type EngineResult<T> = Result<T, EngineError>;
36
37impl EngineError {
38 pub fn template_not_found(name: impl Into<String>) -> Self {
39 Self::TemplateNotFound { name: name.into() }
40 }
41
42 pub fn invalid_config(reason: impl Into<String>) -> Self {
43 Self::InvalidConfig {
44 reason: reason.into(),
45 }
46 }
47
48 pub fn file_error(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
49 Self::FileError {
50 path: path.into(),
51 source,
52 }
53 }
54
55 pub fn variable_error(variable: impl Into<String>, reason: impl Into<String>) -> Self {
56 Self::VariableError {
57 variable: variable.into(),
58 reason: reason.into(),
59 }
60 }
61
62 pub fn feature_dependency_error(
63 feature: impl Into<String>,
64 dependency: impl Into<String>,
65 ) -> Self {
66 Self::FeatureDependencyError {
67 feature: feature.into(),
68 dependency: dependency.into(),
69 }
70 }
71
72 pub fn composition_error(reason: impl Into<String>) -> Self {
73 Self::CompositionError {
74 reason: reason.into(),
75 }
76 }
77}