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-data-is-not-gzip"))]
19 DataIsNotGzip,
20
21 #[error("{msg}", msg = t!("error-duplicate-paths", {
23 "paths" => paths.iter()
24 .map(|p| format!("{p:?}"))
25 .collect::<Vec<_>>()
26 .join("\n")
27 }))]
28 DuplicatePaths {
29 paths: HashSet<PathBuf>,
31 },
32
33 #[cfg(feature = "creation")]
35 #[error("{msg}", msg = t!("error-file-creation", { "source" => .0.to_string() }))]
36 File(#[from] crate::CreationError),
37
38 #[error("{msg}", msg = t!("error-io", {
40 "context" => context,
41 "source" => source.to_string()
42 }))]
43 Io {
44 context: String,
46 source: std::io::Error,
48 },
49
50 #[error("{msg}", msg = t!("error-io-path", {
52 "path" => path,
53 "context" => context,
54 "source" => source.to_string()
55 }))]
56 IoPath {
57 path: PathBuf,
59 context: String,
61 source: std::io::Error,
63 },
64
65 #[error(transparent)]
67 InvalidUTF8(#[from] FromUtf8Error),
68
69 #[error("{msg}", msg = t!("error-invalid-gzip", { "source" => .0.to_string() }))]
71 InvalidGzip(std::io::Error),
72
73 #[error(transparent)]
75 PathValidation(#[from] PathValidationErrors),
76
77 #[error("{msg}", msg = t!("error-parse", { "source" => .0 }))]
79 Parse(String),
80
81 #[error("{msg}", msg = t!("error-interpreter", {
83 "line_number" => .0.to_string(),
84 "line" => .1,
85 "reason" => .2,
86 }))]
87 InterpreterError(usize, String, String),
88
89 #[error("Unsupported schema version: {0}")]
91 UnsupportedSchemaVersion(String),
92}