1use std::fmt;
4
5#[derive(Debug)]
7pub enum Error {
8 Io(std::io::Error),
10 Corrupt {
13 path: String,
15 reason: String,
17 },
18 Format(String),
20 Locked(String),
22 EntryTooLong(usize),
24 OutOfRange(String),
26 Signature(String),
28}
29
30impl fmt::Display for Error {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::Io(e) => write!(f, "store: {e}"),
34 Self::Corrupt { path, reason } => write!(f, "{path}: {reason}"),
35 Self::Format(what) => write!(f, "format: {what}"),
36 Self::Locked(path) => write!(f, "another writer holds {path}"),
37 Self::EntryTooLong(len) => write!(f, "entry of {len} bytes exceeds 65535"),
38 Self::OutOfRange(what) => write!(f, "out of range: {what}"),
39 Self::Signature(what) => write!(f, "signature: {what}"),
40 }
41 }
42}
43
44impl std::error::Error for Error {
45 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
46 match self {
47 Self::Io(e) => Some(e),
48 _ => None,
49 }
50 }
51}
52
53impl From<std::io::Error> for Error {
54 fn from(e: std::io::Error) -> Self {
55 Self::Io(e)
56 }
57}
58
59pub type Result<T> = std::result::Result<T, Error>;