1use std::error::Error as StdError;
2use std::fmt;
3use std::io;
4use std::path::PathBuf;
5
6#[derive(thiserror::Error)]
7pub enum Error {
8 #[error(transparent)]
9 Core(#[from] pkgar_core::Error),
10 #[error("{source} ({path:?}) {context:?}")]
11 Io {
12 #[source]
13 source: io::Error,
14 path: Option<PathBuf>,
15 context: &'static str,
16 },
17 #[error(transparent)]
18 Ser(#[from] toml::ser::Error),
19 #[error(transparent)]
20 Deser(#[from] toml::de::Error),
21 #[error("Invalid cypher key length (expected {expected}, got {actual})")]
22 KeyInvalid { expected: usize, actual: usize },
23 #[error("KeyMismatch")]
24 KeyMismatch,
25 #[error("Invalid nonce length")]
26 NonceInvalid,
27 #[error("Incorrect passphrase")]
28 PassphraseIncorrect,
29 #[error("Passphrases did not match")]
30 PassphraseMismatch,
31}
32
33impl fmt::Debug for Error {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 writeln!(f, "{self}")?;
36
37 let mut source = self.source();
38 while let Some(err) = source {
39 writeln!(f, "\tCaused by: {err}")?;
40 source = err.source();
41 }
42
43 Ok(())
48 }
49}