morphix/
error.rs

1use std::error::Error;
2use std::fmt::Display;
3
4use crate::Path;
5
6/// Error types for mutation operations.
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum MutationError {
10    /// The specified path does not exist.
11    IndexError { path: Path<false> },
12    /// Mutation could not be performed at the specified path.
13    OperationError { path: Path<false> },
14}
15
16impl Display for MutationError {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        match self {
19            Self::IndexError { path } => {
20                write!(f, "path {path} does not exist or is malformed")
21            }
22            Self::OperationError { path } => {
23                write!(f, "operation could not be performed at {path}")
24            }
25        }
26    }
27}
28
29impl Error for MutationError {}