1use std::fmt;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum Error {
9 BadVersion(String),
11 UnsupportedMajor(u64),
13 UnsupportedMinor(u64),
16 EmptyPath(usize),
18 EmptyPathSegment(usize),
20 EmptyAttrName(usize),
22 EmptyValueSet(usize, String),
24 DuplicatePath(Vec<String>),
26}
27
28impl fmt::Display for Error {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 Error::BadVersion(v) => write!(f, "protocol_version is not MAJOR.MINOR.PATCH: {v:?}"),
32 Error::UnsupportedMajor(m) => write!(
33 f,
34 "unsupported protocol MAJOR {m} (this implementation supports {})",
35 crate::SUPPORTED_PROTOCOL_MAJOR
36 ),
37 Error::UnsupportedMinor(m) => write!(
38 f,
39 "unsupported protocol MINOR {m} while MAJOR is 0 (this implementation supports 0.{})",
40 crate::SUPPORTED_PROTOCOL_MINOR
41 ),
42 Error::EmptyPath(i) => write!(f, "node at index {i} has an empty path"),
43 Error::EmptyPathSegment(i) => write!(f, "node at index {i} has an empty path segment"),
44 Error::EmptyAttrName(i) => write!(f, "node at index {i} has an empty attribute name"),
45 Error::EmptyValueSet(i, name) => {
46 write!(f, "node at index {i}: attribute {name:?} has an empty value set")
47 }
48 Error::DuplicatePath(p) => write!(f, "duplicate node path within snapshot: {p:?}"),
49 }
50 }
51}
52
53impl std::error::Error for Error {}