1use fuchsia_merkle::Hash;
6use fuchsia_url::errors::{PackagePathSegmentError, ResourcePathError};
7use std::io;
8use std::path::PathBuf;
9use tempfile::PersistError;
10use thiserror::Error;
11
12#[derive(Debug, Error)]
13pub enum PackageBuildManifestError {
14 #[error("manifest contains an invalid resource path '{}'.", path)]
15 ResourcePath {
16 #[source]
17 cause: ResourcePathError,
18 path: String,
19 },
20
21 #[error("attempted to deserialize creation manifest from malformed json")]
22 Json(#[from] serde_json::Error),
23
24 #[error("package external content cannot be in 'meta/' directory: {}", path)]
25 ExternalContentInMetaDirectory { path: String },
26
27 #[error("package far content must be in 'meta/' directory: {}", path)]
28 FarContentNotInMetaDirectory { path: String },
29
30 #[error("entry has no '=': '{}'", entry)]
31 EntryHasNoEqualsSign { entry: String },
32
33 #[error("duplicate resource path: '{}'", path)]
34 DuplicateResourcePath { path: String },
35
36 #[error("io error")]
37 IoError(#[from] io::Error),
38
39 #[error("error occurred when traverse the contents of a directory")]
40 WalkDir(#[from] walkdir::Error),
41
42 #[error("error occurred when strip prefix from the path")]
43 StripPrefixError(#[from] std::path::StripPrefixError),
44
45 #[error("the resource path is empty")]
46 EmptyResourcePath,
47
48 #[error("manifest contains an invalid file path '{}'.", path.display())]
49 InvalidFileType { path: PathBuf },
50
51 #[error("file directory collision at: {:?}", path)]
52 FileDirectoryCollision { path: String },
53}
54
55#[derive(Debug, Error)]
56pub enum PackageManifestError {
57 #[error("package contains an invalid blob source path '{source_path:?}'. {merkle}")]
58 InvalidBlobPath { merkle: Hash, source_path: PathBuf },
59
60 #[error("package contains an invalid subpackage path '{path:?}'. {merkle}")]
61 InvalidSubpackagePath { merkle: Hash, path: PathBuf },
62
63 #[error("io error")]
64 IoError(#[from] io::Error),
65
66 #[error("io error {cause}: '{path}'")]
67 IoErrorWithPath { cause: io::Error, path: PathBuf },
68
69 #[error("meta contents")]
70 MetaContents(#[from] MetaContentsError),
71
72 #[error("meta package")]
73 MetaPackage(#[from] MetaPackageError),
74
75 #[error("meta subpackages")]
76 MetaSubpackages(#[from] MetaSubpackagesError),
77
78 #[error("archive")]
79 Archive(#[from] fuchsia_archive::Error),
80
81 #[error("writing to relative path failed")]
82 RelativeWrite(#[source] anyhow::Error),
83
84 #[error("persisting to file failed: '{path}'")]
85 Persist {
86 #[source]
87 cause: PersistError,
88 path: PathBuf,
89 },
90
91 #[error("decompressing delivery blob failed: '{path}'")]
92 DecompressDeliveryBlob {
93 #[source]
94 cause: delivery_blob::DecompressError,
95 path: PathBuf,
96 },
97
98 #[error("invalid abi-revision file")]
99 AbiRevision(#[from] AbiRevisionError),
100}
101
102#[derive(Debug, Error)]
103pub enum MetaContentsError {
104 #[error("invalid resource path: '{:?}'", path)]
105 InvalidResourcePath {
106 #[source]
107 cause: ResourcePathError,
108 path: String,
109 },
110
111 #[error("package external content cannot be in 'meta/' directory: '{:?}'", path)]
112 ExternalContentInMetaDirectory { path: String },
113
114 #[error("entry has no '=': '{:?}'", entry)]
115 EntryHasNoEqualsSign { entry: String },
116
117 #[error("duplicate resource path: '{:?}'", path)]
118 DuplicateResourcePath { path: String },
119
120 #[error("io error")]
121 IoError(#[from] io::Error),
122
123 #[error("invalid hash")]
124 ParseHash(#[from] fuchsia_hash::ParseHashError),
125
126 #[error("collision between a file and a directory at path: '{:?}'", path)]
127 FileDirectoryCollision { path: String },
128}
129
130#[derive(Debug, Error)]
131pub enum MetaPackageError {
132 #[error("invalid package name")]
133 PackageName(#[source] PackagePathSegmentError),
134
135 #[error("invalid package variant")]
136 PackageVariant(#[source] PackagePathSegmentError),
137
138 #[error("attempted to deserialize meta/package from malformed json: {}", _0)]
139 Json(#[from] serde_json::Error),
140
141 #[error("meta/package file not found")]
142 MetaPackageMissing,
143}
144
145#[derive(Debug, Error)]
146pub enum AbiRevisionError {
147 #[error("abi-revision file must be 8 bytes")]
148 Invalid(#[from] std::array::TryFromSliceError),
149 #[error("abi-revision file is missing")]
150 Missing,
151}
152
153#[derive(Debug, Error)]
154pub enum MetaSubpackagesError {
155 #[error("invalid subpackage name: '{:?}'", name)]
156 InvalidSubpackageName {
157 #[source]
158 cause: PackagePathSegmentError,
159 name: String,
160 },
161
162 #[error("attempted to deserialize {} from malformed json", crate::MetaSubpackages::PATH)]
163 Json(#[from] serde_json::Error),
164
165 #[error("duplicate subpackage name: '{:?}'", name)]
166 DuplicateSubpackageName { name: String },
167
168 #[error("io error")]
169 IoError(#[from] io::Error),
170
171 #[error("invalid hash")]
172 ParseHash(#[from] fuchsia_hash::ParseHashError),
173}
174
175#[derive(Debug, Error)]
176pub enum BuildError {
177 #[error("io: {}", _0)]
178 IoError(#[from] io::Error),
179
180 #[error("{cause}: '{path}'")]
181 IoErrorWithPath { cause: io::Error, path: PathBuf },
182
183 #[error("meta contents")]
184 MetaContents(#[from] MetaContentsError),
185
186 #[error("meta package")]
187 MetaPackage(#[from] MetaPackageError),
188
189 #[error("meta subpackages")]
190 MetaSubpackages(#[from] MetaSubpackagesError),
191
192 #[error("package name")]
193 PackageName(#[source] PackagePathSegmentError),
194
195 #[error("package manifest")]
196 PackageManifest(#[from] PackageManifestError),
197
198 #[error(
199 "the creation manifest contained a resource path that conflicts with a generated resource path: '{}'",
200 conflicting_resource_path
201 )]
202 ConflictingResource { conflicting_resource_path: String },
203
204 #[error("archive write")]
205 ArchiveWrite(#[from] fuchsia_archive::Error),
206}
207
208impl From<(io::Error, PathBuf)> for BuildError {
209 fn from(pair: (io::Error, PathBuf)) -> Self {
210 Self::IoErrorWithPath { cause: pair.0, path: pair.1 }
211 }
212}
213
214#[derive(Debug, Error, Eq, PartialEq)]
215pub enum ParsePackagePathError {
216 #[error("package path has more than two segments")]
217 TooManySegments,
218
219 #[error("package path has fewer than two segments")]
220 TooFewSegments,
221
222 #[error("invalid package name")]
223 PackageName(#[source] PackagePathSegmentError),
224
225 #[error("invalid package variant")]
226 PackageVariant(#[source] PackagePathSegmentError),
227}