scrivener_rtf/error.rs
1//! Error types for RTF parsing and generation.
2
3use crate::token::Token;
4use thiserror::Error;
5
6/// RTF parsing and generation errors.
7#[derive(Error, Debug)]
8pub enum RtfError {
9 /// Lexer error encountered during tokenization.
10 #[error("Lexer error at position {position}: {message}")]
11 LexError {
12 /// Byte position where the error occurred.
13 position: usize,
14 /// Error description.
15 message: String,
16 },
17
18 /// Parser error encountered during AST construction.
19 #[error("Parse error: {message}")]
20 ParseError {
21 /// Error description.
22 message: String,
23 },
24
25 /// Unexpected token encountered during parsing.
26 #[error("Unexpected token: expected {expected}, found {found:?}")]
27 UnexpectedToken {
28 /// Description of what was expected.
29 expected: String,
30 /// The token that was found.
31 found: Token,
32 },
33
34 /// Unmatched group brace error.
35 #[error("Unmatched group: {0}")]
36 UnmatchedGroup(String),
37
38 /// Unsupported character encoding.
39 #[error("Unsupported encoding: code page {0}")]
40 UnsupportedEncoding(u16),
41
42 /// Error during RTF generation.
43 #[error("Generator error: {0}")]
44 GeneratorError(String),
45
46 /// I/O error during file operations.
47 #[error("IO error: {0}")]
48 Io(#[from] std::io::Error),
49}
50
51/// Result type for RTF operations.
52pub type Result<T> = std::result::Result<T, RtfError>;