1use std::path::PathBuf;
4
5use colored::Colorize;
6use log::SetLoggerError;
7use winnow::error::{ContextError, ParseError};
8
9#[derive(Debug, thiserror::Error)]
11pub enum Error {
12 #[error(transparent)]
14 AlpmBuildinfo(#[from] alpm_buildinfo::Error),
15
16 #[error(transparent)]
18 AlpmPackageInfo(#[from] alpm_pkginfo::Error),
19
20 #[error(transparent)]
22 AlpmMtree(#[from] alpm_mtree::Error),
23
24 #[error(transparent)]
26 AlpmSourceInfo(#[from] alpm_srcinfo::Error),
27
28 #[error(transparent)]
30 AlpmTypes(#[from] alpm_types::Error),
31
32 #[error("Failed to setup the logger:\n{0}")]
34 SetupLogger(#[from] SetLoggerError),
35
36 #[error("Failed to determine the current user's cache directory")]
38 CannotGetCacheDir,
39
40 #[error("A command failed:{message}\nstdout:\n{stdout}\nstderr:\n{stderr}")]
42 CommandFailed {
43 message: String,
45 stdout: String,
47 stderr: String,
49 },
50
51 #[error("An HTTP query failed while {context}:\n{source}")]
52 HttpQueryFailed {
53 context: String,
57 source: reqwest::Error,
59 },
60
61 #[error("I/O error while {context}:\n{source}")]
63 Io {
64 context: String,
68 source: std::io::Error,
70 },
71
72 #[error("I/O error at path {path} while {context}:\n{source}")]
74 IoPath {
75 path: PathBuf,
77 context: String,
81 source: std::io::Error,
83 },
84
85 #[error("JSON error while {context}:\n{source}")]
87 Json {
88 context: String,
92 source: serde_json::Error,
94 },
95
96 #[error("Parser error:\n{0}")]
98 Parser(String),
99
100 #[error("Rsync report error:\n{message}")]
101 RsyncReport { message: String },
102
103 #[error(
105 "The test run failed\n{}",
106 failures
107 .iter()
108 .map(|(index, path, message)| {
109 let index = format!("[{index}]").bold().red();
110 format!("{index} {} failed with error:\n{message}", path.to_string_lossy().bold())})
111 .collect::<Vec<_>>()
112 .join("\n")
113 )]
114 TestFailed {
115 failures: Vec<(usize, PathBuf, String)>,
117 },
118
119 #[error(transparent)]
121 Voa(#[from] voa::Error),
122
123 #[error("Verifying the file {file:?} with signature {signature:?} failed:\n{context}")]
124 VoaVerificationFailed {
125 file: PathBuf,
127 signature: PathBuf,
129 context: String,
131 },
132}
133
134impl<'a> From<ParseError<&'a str, ContextError>> for crate::error::Error {
135 fn from(value: ParseError<&'a str, ContextError>) -> Self {
137 Self::Parser(value.to_string())
138 }
139}