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