alpm_common/
error.rs

1use std::path::{PathBuf, StripPrefixError};
2
3/// An error that can occur when dealing with package inputs.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    /// An I/O error occurred at a path.
7    #[error("I/O error at path {path} while {context}:\n{source}")]
8    IoPath {
9        /// The path at which the error occurred.
10        path: PathBuf,
11        /// The context in which the error occurred.
12        ///
13        /// This is meant to complete the sentence "I/O error at path while ".
14        context: &'static str,
15        /// The source error.
16        source: std::io::Error,
17    },
18
19    /// A path is not a directory.
20    #[error("The path is not a directory: {path:?}")]
21    NotADirectory {
22        /// The path that is not a directory.
23        path: PathBuf,
24    },
25
26    /// One or more paths are not absolute.
27    #[error(
28        "The following paths are not absolute:\n{}",
29        paths.iter().fold(
30            String::new(),
31            |mut output, path| {
32                output.push_str(&format!("{path:?}\n"));
33                output
34            })
35    )]
36    NonAbsolutePaths {
37        /// The list of non-absolute paths.
38        paths: Vec<PathBuf>,
39    },
40
41    /// One or more paths are not relative.
42    #[error(
43        "The following paths are not relative:\n{}",
44        paths.iter().fold(
45            String::new(),
46            |mut output, path| {
47                output.push_str(&format!("{path:?}\n"));
48                output
49            })
50    )]
51    NonRelativePaths {
52        /// The list of non-relative paths.
53        paths: Vec<PathBuf>,
54    },
55
56    /// A path's prefix cannot be stripped.
57    #[error("Cannot strip prefix {prefix} from path {path}:\n{source}")]
58    PathStripPrefix {
59        /// The prefix that is supposed to be stripped from `path`.
60        prefix: PathBuf,
61        /// The path that is supposed to stripped.
62        path: PathBuf,
63        /// The source error.
64        source: StripPrefixError,
65    },
66}