1use std::path::PathBuf;
4
5use colored::Colorize;
6use log::SetLoggerError;
7
8#[derive(Debug, thiserror::Error)]
10pub enum Error {
11 #[error(transparent)]
13 AlpmBuildinfo(#[from] alpm_buildinfo::Error),
14
15 #[error(transparent)]
17 AlpmPackageInfo(#[from] alpm_pkginfo::Error),
18
19 #[error(transparent)]
21 AlpmMtree(#[from] alpm_mtree::Error),
22
23 #[error(transparent)]
25 AlpmSourceInfo(#[from] alpm_srcinfo::Error),
26
27 #[error(transparent)]
29 AlpmTypes(#[from] alpm_types::Error),
30
31 #[error("Failed to setup the logger:\n{0}")]
33 SetupLogger(#[from] SetLoggerError),
34
35 #[error("Failed to determine the current user's cache directory")]
37 CannotGetCacheDir,
38
39 #[error("A command failed:{message}\nstdout:\n{stdout}\nstderr:\n{stderr}")]
41 CommandFailed {
42 message: String,
44 stdout: String,
46 stderr: String,
48 },
49
50 #[error("An HTTP query failed while {context}:\n{source}")]
51 HttpQueryFailed {
52 context: String,
56 source: reqwest::Error,
58 },
59
60 #[error("I/O error while {context}:\n{source}")]
62 Io {
63 context: String,
67 source: std::io::Error,
69 },
70
71 #[error("I/O error at path {path} while {context}:\n{source}")]
73 IoPath {
74 path: PathBuf,
76 context: String,
80 source: std::io::Error,
82 },
83
84 #[error("JSON error while {context}:\n{source}")]
86 Json {
87 context: String,
91 source: serde_json::Error,
93 },
94
95 #[error("Parser error:\n{0}")]
97 Parser(String),
98
99 #[error("Rsync report error:\n{message}")]
100 RsyncReport { message: String },
101
102 #[error(
104 "The test run failed\n{}",
105 failures
106 .iter()
107 .map(|(index, path, message)| {
108 let index = format!("[{index}]").bold().red();
109 format!("{index} {} failed with error:\n{message}", path.to_string_lossy().bold())})
110 .collect::<Vec<_>>()
111 .join("\n")
112 )]
113 TestFailed {
114 failures: Vec<(usize, PathBuf, String)>,
116 },
117
118 #[error(transparent)]
120 Voa(#[from] voa::Error),
121
122 #[error("Verifying the file {file:?} with signature {signature:?} failed:\n{context}")]
123 VoaVerificationFailed {
124 file: PathBuf,
126 signature: PathBuf,
128 context: String,
130 },
131}
132
133impl<'a> From<winnow::error::ParseError<&'a str, winnow::error::ContextError>>
134 for crate::error::Error
135{
136 fn from(value: winnow::error::ParseError<&'a str, winnow::error::ContextError>) -> Self {
138 Self::Parser(value.to_string())
139 }
140}