1use std::{error::Error, fmt::Display, sync::Arc};
2
3pub(crate) type Error_ = anyhow::Error;
4
5pub struct ErrorCollector {
7 vec: Option<Vec<EntryRepackError>>,
8 name: Arc<str>,
9}
10impl ErrorCollector {
11 #[must_use]
13 pub fn new(silent: bool) -> Self { Self { vec: (!silent).then(Vec::new), name: "".into() } }
14
15 pub fn rename(&mut self, name: &str) {
17 self.name = name.into();
18 }
19
20 pub fn collect(&mut self, name: impl Into<Arc<str>>, e: Error_) {
22 if let Some(vec) = self.vec.as_mut() {
23 vec.push(EntryRepackError {
24 parent: self.name.clone(),
25 name: name.into(),
26 inner: e
27 });
28 }
29 }
30
31 #[must_use]
33 pub fn results(&self) -> &[EntryRepackError] {
34 self.vec.as_deref().unwrap_or(&[])
35 }
36}
37
38#[derive(Debug)]
40pub struct EntryRepackError {
41 pub parent: Arc<str>,
43 pub name: Arc<str>,
45 inner: Error_
46}
47impl EntryRepackError {
48 #[must_use]
50 pub fn inner_error(&self) -> &dyn Error {
51 &*self.inner
52 }
53}
54impl Error for EntryRepackError {
55 fn source(&self) -> Option<&(dyn Error + 'static)> {
56 Some(&*self.inner)
57 }
58}
59impl Display for EntryRepackError {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 write!(f, "{} {}: {}", self.parent, self.name, self.inner)
62 }
63}
64
65#[derive(Debug, Clone)]
67pub enum FileIgnoreError {
68 Blacklisted,
70 Signfile
72}
73
74impl Error for FileIgnoreError {}
75impl Display for FileIgnoreError {
76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 f.write_str(match self {
78 Self::Blacklisted => "blacklisted",
79 Self::Signfile => "signfile contains SHA-256 hashes of zipped entries",
80 })
81 }
82}