1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::ops::Range;
use thiserror::Error;
/// Error type for editor buffer validation, range operations, and file I/O.
#[derive(Debug, Error)]
pub enum EditorError {
/// The specified byte offset is out of document bounds.
#[error("byte offset {offset} is out of bounds (document length: {len})")]
OutOfBounds {
/// The requested byte offset.
offset: usize,
/// The total length of the document in bytes.
len: usize,
},
/// The specified row index is out of document line bounds.
#[error("line index {row} is out of bounds (total lines: {total_lines})")]
InvalidRow {
/// The requested row index.
row: usize,
/// The total number of lines in the document.
total_lines: usize,
},
/// The range is invalid because start offset exceeds end offset or document bounds.
#[error("invalid byte range: {range:?} (document length: {len})")]
InvalidRange {
/// The requested byte range.
range: Range<usize>,
/// The total length of the document in bytes.
len: usize,
},
/// The byte offset does not land on a valid UTF-8 character boundary.
#[error("byte offset {offset} is not a valid UTF-8 character boundary")]
InvalidCharBoundary {
/// The invalid byte offset.
offset: usize,
},
/// A search was attempted with an empty pattern.
#[error("search pattern is empty")]
EmptySearchPattern,
/// A regex search pattern failed to compile.
#[error("invalid regex {pattern:?}: {message}")]
InvalidRegex {
/// The offending regex source.
pattern: String,
/// The underlying regex engine error message.
message: String,
},
/// An I/O error occurred during file reading or writing.
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}
/// Specialized Result type for editor operations.
pub type Result<T> = std::result::Result<T, EditorError>;