Skip to main content

mical_cli_config/
error.rs

1use core::fmt;
2use mical_cli_syntax::TextRange;
3
4/// Error encountered during AST-to-Config evaluation.
5#[derive(Clone, Debug, PartialEq, Eq)]
6pub enum ConfigError {
7    /// A required syntax element (key, value, token, etc.) was missing or
8    /// malformed in the AST.  The parser should have already reported the
9    /// corresponding syntax error, so this variant does not distinguish
10    /// between different kinds of missing nodes.
11    MissingSyntax { range: TextRange },
12
13    /// An invalid escape sequence was found in a quoted string or quoted key.
14    InvalidEscape { range: TextRange, sequence: String },
15}
16
17impl fmt::Display for ConfigError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            ConfigError::MissingSyntax { range } => {
21                write!(f, "missing syntax element at {:?}", range)
22            }
23            ConfigError::InvalidEscape { range, sequence } => {
24                write!(f, "invalid escape sequence '{}' at {:?}", sequence, range)
25            }
26        }
27    }
28}