Add source files: main, lib, cli, error, convert, highlight, validate, typescript
This commit is contained in:
77
src/error.rs
Normal file
77
src/error.rs
Normal file
@@ -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<std::io::Error> for ConfigForgeError {
|
||||||
|
fn from(e: std::io::Error) -> Self {
|
||||||
|
ConfigForgeError::IoError {
|
||||||
|
details: e.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<serde_json::Error> for ConfigForgeError {
|
||||||
|
fn from(e: serde_json::Error) -> Self {
|
||||||
|
ConfigForgeError::ParseError {
|
||||||
|
format: "JSON".to_string(),
|
||||||
|
details: e.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<serde_yaml::Error> for ConfigForgeError {
|
||||||
|
fn from(e: serde_yaml::Error) -> Self {
|
||||||
|
ConfigForgeError::ParseError {
|
||||||
|
format: "YAML".to_string(),
|
||||||
|
details: e.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<toml::Error> for ConfigForgeError {
|
||||||
|
fn from(e: toml::Error) -> Self {
|
||||||
|
ConfigForgeError::ParseError {
|
||||||
|
format: "TOML".to_string(),
|
||||||
|
details: e.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ini::Error> for ConfigForgeError {
|
||||||
|
fn from(e: ini::Error) -> Self {
|
||||||
|
ConfigForgeError::ParseError {
|
||||||
|
format: "INI".to_string(),
|
||||||
|
details: e.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type Result<T> = std::result::Result<T, ConfigForgeError>;
|
||||||
Reference in New Issue
Block a user