alpm_mtree/
error.rs

1use std::{collections::HashSet, path::PathBuf, string::FromUtf8Error};
2
3#[cfg(doc)]
4use crate::Mtree;
5use crate::mtree::path_validation_error::PathValidationErrors;
6
7/// The Error that can occur when working with ALPM-MTREE
8#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum Error {
11    /// An alpm-common error.
12    #[error(transparent)]
13    AlpmCommon(#[from] alpm_common::Error),
14
15    /// There are duplicate paths.
16    #[error("The following file system paths are duplicates:\n{}",
17        paths.iter().fold(String::new(), |mut output, path| {
18            output.push_str(&format!("{path:?}\n"));
19            output
20        })
21    )]
22    DuplicatePaths {
23        /// The set of file system paths that are duplicates.
24        paths: HashSet<PathBuf>,
25    },
26
27    /// File creation error.
28    #[cfg(feature = "creation")]
29    #[error("File creation error:\n{0}")]
30    File(#[from] crate::CreationError),
31
32    /// IO error
33    #[error("I/O error while {0}:\n{1}")]
34    Io(&'static str, std::io::Error),
35
36    /// IO error with additional path info for more context.
37    #[error("I/O error at path {0:?} while {1}:\n{2}")]
38    IoPath(PathBuf, &'static str, std::io::Error),
39
40    /// UTF-8 parse error
41    #[error(transparent)]
42    InvalidUTF8(#[from] FromUtf8Error),
43
44    /// No input file given
45    #[error("No input file given.")]
46    NoInputFile,
47
48    /// An error occurred while unpacking a gzip file.
49    #[error("Error while unpacking gzip file:\n{0}")]
50    InvalidGzip(std::io::Error),
51
52    /// Validating paths in a base directory using [`Mtree`] data led to one or more errors.
53    #[error(transparent)]
54    PathValidation(#[from] PathValidationErrors),
55
56    /// A Parsing error that occurred during the winnow file parsing.
57    #[error("File parsing error:\n{0}")]
58    ParseError(String),
59
60    /// An error occurred during the interpretation phase of the language.
61    #[error("Error while interpreting file in line {0}:\nAffected line:\n{1}\n\nReason:\n{2}")]
62    InterpreterError(usize, String, String),
63
64    /// JSON error
65    #[error("JSON error: {0}")]
66    Json(#[from] serde_json::Error),
67
68    /// Unsupported schema version
69    #[error("Unsupported schema version: {0}")]
70    UnsupportedSchemaVersion(String),
71}