use thiserror::Error;
use qubit_common::DataType;
use qubit_value::ValueError;
#[derive(Debug, Error)]
pub enum ConfigError {
#[error("Property not found: {0}")]
PropertyNotFound(String),
#[error("Property '{0}' has no value")]
PropertyHasNoValue(String),
#[error("Type mismatch: expected {expected}, actual {actual}")]
TypeMismatch {
expected: DataType,
actual: DataType,
},
#[error("Type conversion failed: {0}")]
ConversionError(String),
#[error("Index out of bounds: index {index}, length {len}")]
IndexOutOfBounds {
index: usize,
len: usize,
},
#[error("Variable substitution failed: {0}")]
SubstitutionError(String),
#[error("Variable substitution depth exceeded maximum limit: {0}")]
SubstitutionDepthExceeded(usize),
#[error("Configuration merge failed: {0}")]
MergeError(String),
#[error("Property '{0}' is final and cannot be overridden")]
PropertyIsFinal(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Parse error: {0}")]
ParseError(String),
#[error("Configuration error: {0}")]
Other(String),
}
pub type ConfigResult<T> = Result<T, ConfigError>;
impl From<ValueError> for ConfigError {
fn from(err: ValueError) -> Self {
match err {
ValueError::NoValue => ConfigError::PropertyHasNoValue("".to_string()),
ValueError::TypeMismatch { expected, actual } => {
ConfigError::TypeMismatch { expected, actual }
}
ValueError::ConversionFailed { from, to } => {
ConfigError::ConversionError(format!("From {from} to {to}"))
}
ValueError::ConversionError(msg) => ConfigError::ConversionError(msg),
ValueError::IndexOutOfBounds { index, len } => {
ConfigError::IndexOutOfBounds { index, len }
}
}
}
}