1use std::error::Error;
2use std::fmt::Display;
3
4use crate::Path;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum MutationError {
10 IndexError { path: Path<false> },
12 OperationError { path: Path<false> },
14 #[cfg(feature = "truncate")]
16 TruncateError {
17 path: Path<false>,
18 actual_len: usize,
19 truncate_len: usize,
20 },
21}
22
23impl Display for MutationError {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 match self {
26 Self::IndexError { path } => {
27 write!(f, "path {path} does not exist or is malformed")
28 }
29 Self::OperationError { path } => {
30 write!(f, "operation could not be performed at {path}")
31 }
32 Self::TruncateError {
33 path,
34 actual_len,
35 truncate_len,
36 } => {
37 write!(
38 f,
39 "cannot truncate at {path}: actual length {actual_len} is less than truncate length {truncate_len}"
40 )
41 }
42 }
43 }
44}
45
46impl Error for MutationError {}