dev_scripts/
error.rs

1//! Error handling for the `dev-scripts` executable.
2
3use std::path::PathBuf;
4
5use log::SetLoggerError;
6
7/// The error that can occur when using the `dev-scripts` executable.
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10    /// An `alpm_buildinfo::Error` occurred.
11    #[error(transparent)]
12    AlpmBuildinfo(#[from] alpm_buildinfo::Error),
13
14    /// An `alpm_pkginfo::Error` occurred.
15    #[error(transparent)]
16    AlpmPackageInfo(#[from] alpm_pkginfo::Error),
17
18    /// An `alpm_mtree::Error` occurred.
19    #[error(transparent)]
20    AlpmMtree(#[from] alpm_mtree::Error),
21
22    /// An `alpm_srcinfo::Error` occurred.
23    #[error(transparent)]
24    AlpmSourceInfo(#[from] alpm_srcinfo::Error),
25
26    /// An `alpm_types::Error` occurred.
27    #[error(transparent)]
28    AlpmTypes(#[from] alpm_types::Error),
29
30    /// The logger cannot be setup.
31    #[error("Failed to setup the logger:\n{0}")]
32    SetupLogger(#[from] SetLoggerError),
33
34    /// It is not possible to get the cache directory for the current user.
35    #[error("Failed to determine the current user's cache directory")]
36    CannotGetCacheDir,
37
38    /// A command failed.
39    #[error("A command failed:{message}\nstdout:\n{stdout}\nstderr:\n{stderr}")]
40    CommandFailed {
41        /// A message explaining what command failed.
42        message: String,
43        /// The stdout of the failed command.
44        stdout: String,
45        /// The stderr of the failed command.
46        stderr: String,
47    },
48
49    #[error("An HTTP query failed while {context}:\n{source}")]
50    HttpQueryFailed {
51        /// The context in which the error occurred.
52        ///
53        /// This is meant to complete the sentence "An HTTP query failed while {context}".
54        context: String,
55        /// The source error.
56        source: reqwest::Error,
57    },
58
59    /// An I/O error occurred.
60    #[error("I/O error while {context}:\n{source}")]
61    Io {
62        /// The context in which the error occurred.
63        ///
64        /// This is meant to complete the sentence "I/O error while ".
65        context: String,
66        /// The source error.
67        source: std::io::Error,
68    },
69
70    /// An I/O error occurred at a path.
71    #[error("I/O error at path {path} while {context}:\n{source}")]
72    IoPath {
73        /// The path at which the error occurred.
74        path: PathBuf,
75        /// The context in which the error occurred.
76        ///
77        /// This is meant to complete the sentence "I/O error at path while ".
78        context: String,
79        /// The source error.
80        source: std::io::Error,
81    },
82
83    /// A JSON error occurred.
84    #[error("JSON error while {context}:\n{source}")]
85    Json {
86        /// The context in which the error occurred.
87        ///
88        /// This is meant to complete the sentence "JSON error while ".
89        context: String,
90        /// The source error.
91        source: serde_json::Error,
92    },
93
94    /// A winnow parser for a type didn't work and produced an error.
95    #[error("Parser error:\n{0}")]
96    Parser(String),
97
98    #[error("Rsync report error:\n{message}")]
99    RsyncReport { message: String },
100
101    /// A `voa::Error` occurred.
102    #[error(transparent)]
103    Voa(#[from] voa::Error),
104
105    #[error("Verifying the file {file:?} with signature {signature:?} failed:\n{context}")]
106    VoaVerificationFailed {
107        /// The path of the data file that failed verification.
108        file: PathBuf,
109        /// The path of the signature file that failed verification.
110        signature: PathBuf,
111        /// Additional context.
112        context: String,
113    },
114}
115
116impl<'a> From<winnow::error::ParseError<&'a str, winnow::error::ContextError>>
117    for crate::error::Error
118{
119    /// Converts a [`winnow::error::ParseError`] into an [`Error::Parser`].
120    fn from(value: winnow::error::ParseError<&'a str, winnow::error::ContextError>) -> Self {
121        Self::Parser(value.to_string())
122    }
123}