libpass/errors.rs
1#[cfg(nightly)]
2use std::backtrace::Backtrace;
3use std::io;
4use std::path::PathBuf;
5use thiserror::Error;
6
7/// Errors that may returned by library functions
8#[derive(Error, Debug)]
9pub enum PassError {
10 /// Indication that there doesn't exist a password store at a given location
11 #[error("No password store was found at {0}")]
12 PasswordStoreNotFound(PathBuf),
13
14 /// The on-disk password store is somehow incorrectly formatted
15 #[error("The pass store at {0} is incorrectly formatted: {1}")]
16 InvalidStoreFormat(PathBuf, String),
17
18 /// The requested entry could not be clearly identified because it is ambiguous
19 #[error("Password name {0} is ambiguous because it references a directory as well as a file inside the store")]
20 AmbiguousPassName(String),
21
22 /// The requested entry was not found in the password store
23 #[error("The requested entry ({0}) was not found in the password store")]
24 EntryNotFound(String),
25
26 /// An on-disk path could not be correctly interpreted by this program
27 ///
28 /// This can happen because rust imposes that all strings must be valid UTF-8 but some operating systems
29 /// don't impose the same restrictions on their file paths.
30 /// When trying to convert from a path (which is represented using [`OsString`](std::ffi::OsString)) to a
31 /// rust string, this error is returned.
32 #[error("Could not decode the path {0} as UTF-8 string")]
33 PathDecodingError(PathBuf),
34
35 /// A gpg key was tried to be loaded but it could not be
36 #[error("Could not load the gpg key {0}")]
37 GpgKeyNotFoundError(String),
38
39 /// Some IO error occurred that is preserved as `source`
40 #[error("IO Error")]
41 IOError {
42 /// The underlying error
43 #[from]
44 source: io::Error,
45 #[cfg(nightly)]
46 backtrace: Backtrace,
47 },
48
49 /// Some error occurred during entry interaction that is preserved as `source`
50 #[error("GPG error")]
51 GpgError {
52 /// The underlying error
53 #[from]
54 source: gpgme::Error,
55 #[cfg(nightly)]
56 backtrace: Backtrace,
57 },
58}