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