diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..6e47893 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,77 @@ +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum ConfigForgeError { + #[error("Unsupported format '{format}'. Supported formats: json, yaml, toml, env, ini")] + UnsupportedFormat { format: String }, + + #[error("File '{path}' not found")] + FileNotFound { path: String }, + + #[error("Failed to parse {format} file: {details}")] + ParseError { format: String, details: String }, + + #[error("Validation failed at {path}: {reason}")] + ValidationError { path: String, reason: String }, + + #[error("Invalid JSON Schema: {details}")] + SchemaParseError { details: String }, + + #[error("IO error: {details}")] + IoError { details: String }, + + #[error("Conversion error: {details}")] + ConversionError { details: String }, + + #[error("Schema inference error: {details}")] + SchemaInferenceError { details: String }, + + #[error("TypeScript generation error: {details}")] + TypeScriptError { details: String }, +} + +impl From for ConfigForgeError { + fn from(e: std::io::Error) -> Self { + ConfigForgeError::IoError { + details: e.to_string(), + } + } +} + +impl From for ConfigForgeError { + fn from(e: serde_json::Error) -> Self { + ConfigForgeError::ParseError { + format: "JSON".to_string(), + details: e.to_string(), + } + } +} + +impl From for ConfigForgeError { + fn from(e: serde_yaml::Error) -> Self { + ConfigForgeError::ParseError { + format: "YAML".to_string(), + details: e.to_string(), + } + } +} + +impl From for ConfigForgeError { + fn from(e: toml::Error) -> Self { + ConfigForgeError::ParseError { + format: "TOML".to_string(), + details: e.to_string(), + } + } +} + +impl From for ConfigForgeError { + fn from(e: ini::Error) -> Self { + ConfigForgeError::ParseError { + format: "INI".to_string(), + details: e.to_string(), + } + } +} + +pub type Result = std::result::Result;