alpm_mtree/
error.rs

1use std::{collections::HashSet, path::PathBuf, string::FromUtf8Error};
2
3use fluent_i18n::t;
4
5#[cfg(doc)]
6use crate::Mtree;
7use crate::mtree::path_validation_error::PathValidationErrors;
8
9/// The Error that can occur when working with ALPM-MTREE.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum Error {
13    /// An alpm-common error.
14    #[error(transparent)]
15    AlpmCommon(#[from] alpm_common::Error),
16
17    /// There are duplicate paths.
18    #[error("{msg}", msg = t!("error-duplicate-paths", {
19        "paths" => paths.iter()
20            .map(|p| format!("{p:?}"))
21            .collect::<Vec<_>>()
22            .join("\n")
23    }))]
24    DuplicatePaths {
25        /// The set of file system paths that are duplicates.
26        paths: HashSet<PathBuf>,
27    },
28
29    /// File creation error.
30    #[cfg(feature = "creation")]
31    #[error("{msg}", msg = t!("error-file-creation", { "source" => .0.to_string() }))]
32    File(#[from] crate::CreationError),
33
34    /// IO error.
35    #[error("{msg}", msg = t!("error-io", {
36        "context" => context,
37        "source" => source.to_string()
38    }))]
39    Io {
40        /// The context of the error.
41        context: String,
42        /// The underlying IO error.
43        source: std::io::Error,
44    },
45
46    /// IO error with additional path info for more context.
47    #[error("{msg}", msg = t!("error-io-path", {
48        "path" => path,
49        "context" => context,
50        "source" => source.to_string()
51    }))]
52    IoPath {
53        /// The path related to the error.
54        path: PathBuf,
55        /// The context of the error.
56        context: String,
57        /// The underlying IO error.
58        source: std::io::Error,
59    },
60
61    /// UTF-8 parse error.
62    #[error(transparent)]
63    InvalidUTF8(#[from] FromUtf8Error),
64
65    /// An error occurred while unpacking a gzip file.
66    #[error("{msg}", msg = t!("error-invalid-gzip", { "source" => .0.to_string() }))]
67    InvalidGzip(std::io::Error),
68
69    /// Validating paths in a base directory using [`Mtree`] data led to one or more errors.
70    #[error(transparent)]
71    PathValidation(#[from] PathValidationErrors),
72
73    /// A parsing error that occurred during the winnow file parsing.
74    #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
75    ParseError(String),
76
77    /// An error occurred during the interpretation phase of the language.
78    #[error("{msg}", msg = t!("error-interpreter", {
79        "line_number" => .0.to_string(),
80        "line" => .1,
81        "reason" => .2,
82    }))]
83    InterpreterError(usize, String, String),
84
85    /// Unsupported schema version
86    #[error("Unsupported schema version: {0}")]
87    UnsupportedSchemaVersion(String),
88}