1#![forbid(unsafe_code)]
2#![warn(missing_docs)]
3
4use core::fmt;
7
8pub type Result<T> = core::result::Result<T, PrikkError>;
10
11#[derive(Debug, Clone, PartialEq, Eq)]
13pub enum PrikkError {
14 CanonicalEncoding(String),
16 InvalidObjectId(String),
18 InvalidSignature(String),
20 InvalidName(String),
22 ObjectTypeMismatch {
24 expected: String,
26 actual: String,
28 },
29 UnsupportedFormatVersion(u32),
31 MalformedData(String),
33 Integrity(String),
35 LockConflict(String),
37 UnsupportedObjectType(String),
39 Io(String),
41}
42
43impl fmt::Display for PrikkError {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 match self {
46 Self::CanonicalEncoding(msg) => write!(f, "canonical encoding error: {msg}"),
47 Self::InvalidObjectId(msg) => write!(f, "invalid object id: {msg}"),
48 Self::InvalidSignature(msg) => write!(f, "invalid signature: {msg}"),
49 Self::InvalidName(msg) => write!(f, "invalid name: {msg}"),
50 Self::ObjectTypeMismatch { expected, actual } => {
51 write!(f, "object type mismatch: expected {expected}, got {actual}")
52 }
53 Self::UnsupportedFormatVersion(version) => {
54 write!(f, "unsupported format version: {version}")
55 }
56 Self::MalformedData(msg) => write!(f, "malformed persisted data: {msg}"),
57 Self::Integrity(msg) => write!(f, "integrity error: {msg}"),
58 Self::LockConflict(msg) => write!(f, "lock conflict: {msg}"),
59 Self::UnsupportedObjectType(msg) => write!(f, "unsupported object type: {msg}"),
60 Self::Io(msg) => write!(f, "i/o error: {msg}"),
61 }
62 }
63}
64
65impl std::error::Error for PrikkError {}
66
67impl From<std::io::Error> for PrikkError {
68 fn from(value: std::io::Error) -> Self {
69 Self::Io(value.to_string())
70 }
71}