jaml/parser/
error.rs

1use super::{indent, parse::PestError};
2
3/// Errors that can occur during parsing.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7    /// Error from the pest parser (syntax errors).
8    #[error("Parse error: {0}")]
9    PestError(#[from] PestError),
10
11    /// Integer parsing or overflow error.
12    #[error("Integer parse error: {0}")]
13    ParseIntError(#[from] std::num::ParseIntError),
14
15    /// Float parsing error.
16    #[error("Float parse error: {0}")]
17    ParseFloatError(#[from] std::num::ParseFloatError),
18
19    /// Base64 decoding error.
20    #[error("Base64 decode error: {0}")]
21    Base64DecodeError(#[from] base64::DecodeError),
22
23    /// Invalid escape sequence in string.
24    #[error("Invalid escape character: {0}")]
25    InvalidEscapeChar(char),
26
27    /// Invalid unicode escape sequence.
28    #[error("Invalid unicode escape: {0}")]
29    InvalidUnicodeEscape(String),
30
31    /// Invalid unicode codepoint.
32    #[error("Invalid unicode codepoint: {0}")]
33    InvalidUnicodeCodepoint(u32),
34
35    /// Hex binary with odd number of digits.
36    #[error("Hex binary must have even number of digits")]
37    OddHexDigits,
38
39    /// Duplicate key in map.
40    #[error("Duplicate key in map: {0}")]
41    DuplicateKey(String),
42
43    /// Invalid timestamp format.
44    #[error("Invalid timestamp '{0}': {1}")]
45    InvalidTimestamp(String, String),
46
47    /// Mixed tabs and spaces in indentation base unit.
48    #[error("Mixed tabs and spaces in indentation, got '{0:?}'")]
49    MixedIndent(String),
50
51    /// Inconsistent indentation type (switching between spaces and tabs).
52    #[error("Inconsistent indent char: expected '{0}', got '{1}'")]
53    InconsistentIndentTab(indent::Tab, indent::Tab),
54
55    /// Invalid indentation (not a multiple of the base unit).
56    #[error("Invalid indentation: expected multiple of {0}, got {1}")]
57    InvalidIndentCount(usize, usize),
58
59    /// Unexpected indentation level.
60    #[error("Unexpected indentation: expected {0}, got {1}")]
61    UnexpectedIndent(usize, usize),
62
63    /// Empty document.
64    #[error("Empty document")]
65    EmptyDocument,
66
67    /// Missing value for list item or map entry.
68    #[error("Missing value at line {0}")]
69    MissingValue(usize),
70}
71
72/// Result type for parsing operations.
73pub type Result<T> = std::result::Result<T, Error>;