alpm_common/
error.rs

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