1use thiserror::Error;
18
19use qubit_common::DataType;
20use qubit_value::ValueError;
21
22#[derive(Debug, Error)]
38pub enum ConfigError {
39 #[error("Property not found: {0}")]
41 PropertyNotFound(String),
42
43 #[error("Property '{0}' has no value")]
45 PropertyHasNoValue(String),
46
47 #[error("Type mismatch: expected {expected}, actual {actual}")]
49 TypeMismatch {
50 expected: DataType,
52 actual: DataType,
54 },
55
56 #[error("Type conversion failed: {0}")]
58 ConversionError(String),
59
60 #[error("Index out of bounds: index {index}, length {len}")]
62 IndexOutOfBounds {
63 index: usize,
65 len: usize,
67 },
68
69 #[error("Variable substitution failed: {0}")]
71 SubstitutionError(String),
72
73 #[error("Variable substitution depth exceeded maximum limit: {0}")]
75 SubstitutionDepthExceeded(usize),
76
77 #[error("Configuration merge failed: {0}")]
79 MergeError(String),
80
81 #[error("Property '{0}' is final and cannot be overridden")]
83 PropertyIsFinal(String),
84
85 #[error("IO error: {0}")]
87 IoError(#[from] std::io::Error),
88
89 #[error("Parse error: {0}")]
91 ParseError(String),
92
93 #[error("Configuration error: {0}")]
95 Other(String),
96}
97
98pub type ConfigResult<T> = Result<T, ConfigError>;
102
103impl From<ValueError> for ConfigError {
104 fn from(err: ValueError) -> Self {
105 match err {
106 ValueError::NoValue => ConfigError::PropertyHasNoValue("".to_string()),
107 ValueError::TypeMismatch { expected, actual } => {
108 ConfigError::TypeMismatch { expected, actual }
109 }
110 ValueError::ConversionFailed { from, to } => {
111 ConfigError::ConversionError(format!("From {from} to {to}"))
112 }
113 ValueError::ConversionError(msg) => ConfigError::ConversionError(msg),
114 ValueError::IndexOutOfBounds { index, len } => {
115 ConfigError::IndexOutOfBounds { index, len }
116 }
117 }
118 }
119}