alpm_package/
error.rs

1//! Error handling.
2
3use std::{path::PathBuf, string::FromUtf8Error};
4
5use alpm_types::MetadataFileName;
6use fluent_i18n::t;
7
8/// An error that can occur when dealing with alpm-package.
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11    /// An [`alpm_buildinfo::Error`].
12    #[error(transparent)]
13    AlpmBuildInfo(#[from] alpm_buildinfo::Error),
14
15    /// An [`alpm_common::Error`].
16    #[error(transparent)]
17    AlpmCommon(#[from] alpm_common::Error),
18
19    /// An [`alpm_mtree::Error`].
20    #[error(transparent)]
21    AlpmMtree(#[from] alpm_mtree::Error),
22
23    /// An [`alpm_mtree::mtree::path_validation_error::PathValidationError`].
24    #[error(transparent)]
25    AlpmMtreePathValidation(#[from] alpm_mtree::mtree::path_validation_error::PathValidationError),
26
27    /// An [`alpm_pkginfo::Error`].
28    #[error(transparent)]
29    AlpmPackageInfo(#[from] alpm_pkginfo::Error),
30
31    /// An [`alpm_types::Error`].
32    #[error(transparent)]
33    AlpmTypes(#[from] alpm_types::Error),
34
35    /// An [`alpm_types::PackageError`].
36    #[error(transparent)]
37    AlpmTypesPackage(#[from] alpm_types::PackageError),
38
39    /// An [`alpm_compress::Error`].
40    #[error(transparent)]
41    AlpmCompress(#[from] alpm_compress::Error),
42
43    /// An error with an [alpm-install-scriptlet].
44    ///
45    /// [alpm-install-scriptlet]: https://alpm.archlinux.page/specifications/alpm-install-scriptlet.5.html
46    #[error("{msg}", msg = t!("error-install-scriptlet", {
47        "path" => path,
48        "context" => context
49    }))]
50    InstallScriptlet {
51        /// The path to the alpm-install-scriptlet.
52        path: PathBuf,
53        /// The context in which the error occurred.
54        ///
55        /// This is meant to complete the sentence "The alpm-install-scriptlet at {path} is invalid
56        /// because {context}".
57        context: String,
58    },
59
60    /// A package input error.
61    #[error("{msg}", msg = t!("error-package-input", { "source" => 0.to_string() }))]
62    Input(#[from] crate::input::Error),
63
64    /// A package input directory is also used as the package output directory.
65    #[error("{msg}", msg = t!("error-input-dir-is-output-dir", { "path" => path }))]
66    InputDirIsOutputDir {
67        /// The path used as both input and output.
68        path: PathBuf,
69    },
70
71    /// A package output directory is located inside of a package input directory.
72    #[error("{msg}", msg = t!("error-input-dir-in-output-dir", {
73        "input_path" => input_path,
74        "output_path" => output_path,
75    }))]
76    InputDirInOutputDir {
77        /// The input directory path.
78        input_path: PathBuf,
79        /// The output directory path.
80        output_path: PathBuf,
81    },
82
83    /// An I/O error occurred at a path.
84    #[error("{msg}", msg = t!("error-io-path", {
85        "path" => path,
86        "context" => context,
87        "source" => source.to_string()
88    }))]
89    IoPath {
90        /// The path at which the error occurred.
91        path: PathBuf,
92        /// The context in which the error occurred.
93        ///
94        /// This is meant to complete the sentence "I/O error at path while ".
95        context: String,
96        /// The source error.
97        source: std::io::Error,
98    },
99
100    /// An I/O error occurred while reading.
101    #[error("{msg}", msg = t!("error-io-read", {
102        "context" => context,
103        "source" => source.to_string()
104    }))]
105    IoRead {
106        /// The context in which the error occurred.
107        ///
108        /// This is meant to complete the sentence "I/O read error while ".
109        context: String,
110        /// The source error.
111        source: std::io::Error,
112    },
113
114    /// UTF-8 parse error.
115    #[error("{msg}", msg = t!("error-invalid-utf8", {
116        "context" => context,
117        "source" => source.to_string()
118    }))]
119    InvalidUTF8 {
120        /// The context in which the error occurred.
121        ///
122        /// This is meant to complete the sentence "Invalid UTF-8 while {context}".
123        context: String,
124        /// The source error.
125        source: FromUtf8Error,
126    },
127
128    /// Metadata file not found in package.
129    #[error("{msg}", msg = t!("error-metadata-not-found", { "name" => name.to_string() }))]
130    MetadataFileNotFound {
131        /// The metadata file that was not found.
132        name: MetadataFileName,
133    },
134
135    /// Reached the end of known entries while reading a package.
136    #[error("{msg}", msg = t!("error-end-of-entries"))]
137    EndOfPackageEntries,
138
139    /// A package input directory is located inside of a package output directory.
140    #[error("{msg}", msg = t!("error-output-dir-in-input-dir", {
141        "input_path" => input_path,
142        "output_path" => output_path
143    }))]
144    OutputDirInInputDir {
145        /// The input directory path.
146        input_path: PathBuf,
147        /// The output directory path.
148        output_path: PathBuf,
149    },
150
151    /// A [`crate::package::Error`].
152    #[error("{msg}", msg = t!("error-package", { "source" => .0.to_string() }))]
153    Package(#[from] crate::package::Error),
154
155    /// A path does not exist.
156    #[error("{msg}", msg = t!("error-path-not-exist", { "path" => path }))]
157    PathDoesNotExist {
158        /// The path that should exist.
159        path: PathBuf,
160    },
161
162    /// A path does not have a parent.
163    #[error("{msg}", msg = t!("error-path-no-parent", { "path" => path }))]
164    PathHasNoParent {
165        /// The path that should have a parent.
166        path: PathBuf,
167    },
168
169    /// A path is not a file.
170    #[error("{msg}", msg = t!("error-path-not-file", { "path" => path }))]
171    PathIsNotAFile {
172        /// The path that is not a file.
173        path: PathBuf,
174    },
175
176    /// A path is read only.
177    #[error("{msg}", msg = t!("error-path-read-only", { "path" => path }))]
178    PathIsReadOnly {
179        /// The path that is read only.
180        path: PathBuf,
181    },
182}