textum/snip/snippet/
error.rs

1use crate::snip::target::error::TargetError;
2use crate::snip::BoundaryError;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5/// Errors that can occur during snippet operations.
6pub enum SnippetError {
7    /// An error occurred in boundary resolution.
8    BoundaryError(BoundaryError),
9    /// The resolved range is invalid (start >= end).
10    InvalidRange {
11        /// Starting index of the invalid range.
12        start: usize,
13        /// Ending index of the invalid range.
14        end: usize,
15    },
16    /// The replacement string contains invalid UTF-8.
17    InvalidUtf8(String),
18    /// The resolved index is out of bounds.
19    OutOfBounds {
20        /// The index that exceeded bounds.
21        index: usize,
22        /// The length of the rope.
23        rope_len: usize,
24    },
25}
26
27impl From<BoundaryError> for SnippetError {
28    fn from(err: BoundaryError) -> Self {
29        SnippetError::BoundaryError(err)
30    }
31}
32
33impl From<TargetError> for SnippetError {
34    fn from(err: TargetError) -> Self {
35        // Wrap TargetError in BoundaryError, then in SnippetError
36        SnippetError::BoundaryError(BoundaryError::TargetError(err))
37    }
38}