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#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum Error {
13 #[error(transparent)]
15 AlpmCommon(#[from] alpm_common::Error),
16
17 #[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 paths: HashSet<PathBuf>,
27 },
28
29 #[cfg(feature = "creation")]
31 #[error("{msg}", msg = t!("error-file-creation", { "source" => .0.to_string() }))]
32 File(#[from] crate::CreationError),
33
34 #[error("{msg}", msg = t!("error-io", {
36 "context" => context,
37 "source" => source.to_string()
38 }))]
39 Io {
40 context: String,
42 source: std::io::Error,
44 },
45
46 #[error("{msg}", msg = t!("error-io-path", {
48 "path" => path,
49 "context" => context,
50 "source" => source.to_string()
51 }))]
52 IoPath {
53 path: PathBuf,
55 context: String,
57 source: std::io::Error,
59 },
60
61 #[error(transparent)]
63 InvalidUTF8(#[from] FromUtf8Error),
64
65 #[error("{msg}", msg = t!("error-invalid-gzip", { "source" => .0.to_string() }))]
67 InvalidGzip(std::io::Error),
68
69 #[error(transparent)]
71 PathValidation(#[from] PathValidationErrors),
72
73 #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
75 ParseError(String),
76
77 #[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 #[error("Unsupported schema version: {0}")]
87 UnsupportedSchemaVersion(String),
88}