dir_cache/
error.rs

1use std::fmt::{Display, Formatter};
2
3pub type Result<T> = core::result::Result<T, Error>;
4#[derive(Debug)]
5pub enum Error {
6    Arithmetic(&'static str),
7    ParseManifest(String),
8    ParseMetadata(String),
9    SystemTime(std::time::SystemTimeError),
10    Open(String),
11    WriteContent(String, Option<std::io::Error>),
12    ReadContent(String, Option<std::io::Error>),
13    DeleteContent(String, Option<std::io::Error>),
14    InsertWithErr(Box<dyn std::error::Error>),
15    DangerousKey(String),
16    EncodingError(String),
17    PathRelativize(String),
18}
19
20impl Display for Error {
21    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22        match self {
23            Error::Arithmetic(s) => f.write_fmt(format_args!("Arithmetic failed: {s}")),
24            Error::SystemTime(e) => f.write_fmt(format_args!("Failed to get system time: {e}")),
25            Error::WriteContent(p, e) => f.write_fmt(format_args!(
26                "Failed to write content to disk at {p:?}, source: {e:?}"
27            )),
28            Error::ReadContent(p, e) => f.write_fmt(format_args!(
29                "Failed to read content from disk at {p:?}, source: {e:?}"
30            )),
31            Error::DeleteContent(p, e) => f.write_fmt(format_args!(
32                "Failed to delete content from disk at {p:?}, source: {e:?}"
33            )),
34            Error::ParseManifest(e) => {
35                f.write_fmt(format_args!("Failed to parse manifest, cause: {e}"))
36            }
37            Error::Open(s) => f.write_fmt(format_args!("Bad manifest path: {s}")),
38            Error::InsertWithErr(user) => {
39                f.write_fmt(format_args!("Failed to insert with: {user}"))
40            }
41            Error::ParseMetadata(s) => f.write_fmt(format_args!("Failed to parse metadata: '{s}'")),
42            Error::DangerousKey(e) => f.write_fmt(format_args!("Dangerous key used: {e}")),
43            Error::EncodingError(e) => f.write_fmt(format_args!("Failed to encode content: {e}")),
44            Error::PathRelativize(s) => {
45                f.write_fmt(format_args!("Failed to relativize paths: {s}"))
46            }
47        }
48    }
49}