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
99#[derive(Debug, Error)]
100pub enum MetaContentsError {
101 #[error("invalid resource path: '{:?}'", path)]
102 InvalidResourcePath {
103 #[source]
104 cause: ResourcePathError,
105 path: String,
106 },
107
108 #[error("package external content cannot be in 'meta/' directory: '{:?}'", path)]
109 ExternalContentInMetaDirectory { path: String },
110
111 #[error("entry has no '=': '{:?}'", entry)]
112 EntryHasNoEqualsSign { entry: String },
113
114 #[error("duplicate resource path: '{:?}'", path)]
115 DuplicateResourcePath { path: String },
116
117 #[error("io error")]
118 IoError(#[from] io::Error),
119
120 #[error("invalid hash")]
121 ParseHash(#[from] fuchsia_hash::ParseHashError),
122
123 #[error("collision between a file and a directory at path: '{:?}'", path)]
124 FileDirectoryCollision { path: String },
125}
126
127#[derive(Debug, Error)]
128pub enum MetaPackageError {
129 #[error("invalid package name")]
130 PackageName(#[source] PackagePathSegmentError),
131
132 #[error("invalid package variant")]
133 PackageVariant(#[source] PackagePathSegmentError),
134
135 #[error("attempted to deserialize meta/package from malformed json: {}", _0)]
136 Json(#[from] serde_json::Error),
137
138 #[error("meta/package file not found")]
139 MetaPackageMissing,
140}
141
142#[derive(Debug, Error)]
143pub enum MetaSubpackagesError {
144 #[error("invalid subpackage name: '{:?}'", name)]
145 InvalidSubpackageName {
146 #[source]
147 cause: PackagePathSegmentError,
148 name: String,
149 },
150
151 #[error("attempted to deserialize {} from malformed json", crate::MetaSubpackages::PATH)]
152 Json(#[from] serde_json::Error),
153
154 #[error("duplicate subpackage name: '{:?}'", name)]
155 DuplicateSubpackageName { name: String },
156
157 #[error("io error")]
158 IoError(#[from] io::Error),
159
160 #[error("invalid hash")]
161 ParseHash(#[from] fuchsia_hash::ParseHashError),
162}
163
164#[derive(Debug, Error)]
165pub enum BuildError {
166 #[error("io: {}", _0)]
167 IoError(#[from] io::Error),
168
169 #[error("{cause}: '{path}'")]
170 IoErrorWithPath { cause: io::Error, path: PathBuf },
171
172 #[error("meta contents")]
173 MetaContents(#[from] MetaContentsError),
174
175 #[error("meta package")]
176 MetaPackage(#[from] MetaPackageError),
177
178 #[error("meta subpackages")]
179 MetaSubpackages(#[from] MetaSubpackagesError),
180
181 #[error("package name")]
182 PackageName(#[source] PackagePathSegmentError),
183
184 #[error("package manifest")]
185 PackageManifest(#[from] PackageManifestError),
186
187 #[error(
188 "the creation manifest contained a resource path that conflicts with a generated resource path: '{}'",
189 conflicting_resource_path
190 )]
191 ConflictingResource { conflicting_resource_path: String },
192
193 #[error("archive write")]
194 ArchiveWrite(#[from] fuchsia_archive::Error),
195}
196
197impl From<(io::Error, PathBuf)> for BuildError {
198 fn from(pair: (io::Error, PathBuf)) -> Self {
199 Self::IoErrorWithPath { cause: pair.0, path: pair.1 }
200 }
201}
202
203#[derive(Debug, Error, Eq, PartialEq)]
204pub enum ParsePackagePathError {
205 #[error("package path has more than two segments")]
206 TooManySegments,
207
208 #[error("package path has fewer than two segments")]
209 TooFewSegments,
210
211 #[error("invalid package name")]
212 PackageName(#[source] PackagePathSegmentError),
213
214 #[error("invalid package variant")]
215 PackageVariant(#[source] PackagePathSegmentError),
216}