fidl_fuchsia_pkg_ext/
errors.rs
1use thiserror::Error;
6
7#[derive(Debug, Error, Clone)]
8pub enum ResolveError {
9 #[error("the resolver encountered an otherwise unspecified error while handling the request")]
10 Internal,
11
12 #[error("the resolver does not have permission to fetch a package blob")]
13 AccessDenied,
14
15 #[error("some unspecified error during I/O")]
16 Io,
17
18 #[error("the blob does not exist")]
19 BlobNotFound,
20
21 #[error("the package does not exist")]
22 PackageNotFound,
23
24 #[error("the resolver does not know about the repo")]
25 RepoNotFound,
26
27 #[error("there is no space available to store the package or metadata")]
28 NoSpace,
29
30 #[error("the resolver is currently unable to fetch a package blob")]
31 UnavailableBlob,
32
33 #[error("the resolver is currently unable to fetch a repository's metadata")]
34 UnavailableRepoMetadata,
35
36 #[error("the `package_url` provided to resolver is invalid")]
37 InvalidUrl,
38
39 #[error("the `context` provided to resolver is invalid")]
40 InvalidContext,
41}
42
43impl From<fidl_fuchsia_pkg::ResolveError> for ResolveError {
44 fn from(e: fidl_fuchsia_pkg::ResolveError) -> Self {
45 use fidl_fuchsia_pkg::ResolveError as ferror;
46 use ResolveError::*;
47 match e {
48 ferror::Internal => Internal,
49 ferror::AccessDenied => AccessDenied,
50 ferror::Io => Io,
51 ferror::BlobNotFound => BlobNotFound,
52 ferror::PackageNotFound => PackageNotFound,
53 ferror::RepoNotFound => RepoNotFound,
54 ferror::NoSpace => NoSpace,
55 ferror::UnavailableBlob => UnavailableBlob,
56 ferror::UnavailableRepoMetadata => UnavailableRepoMetadata,
57 ferror::InvalidUrl => InvalidUrl,
58 ferror::InvalidContext => InvalidContext,
59 }
60 }
61}
62
63impl From<ResolveError> for fidl_fuchsia_pkg::ResolveError {
64 fn from(e: ResolveError) -> Self {
65 use fidl_fuchsia_pkg::ResolveError as ferror;
66 use ResolveError::*;
67 match e {
68 Internal => ferror::Internal,
69 AccessDenied => ferror::AccessDenied,
70 Io => ferror::Io,
71 BlobNotFound => ferror::BlobNotFound,
72 PackageNotFound => ferror::PackageNotFound,
73 RepoNotFound => ferror::RepoNotFound,
74 NoSpace => ferror::NoSpace,
75 UnavailableBlob => ferror::UnavailableBlob,
76 UnavailableRepoMetadata => ferror::UnavailableRepoMetadata,
77 InvalidUrl => ferror::InvalidUrl,
78 InvalidContext => ferror::InvalidContext,
79 }
80 }
81}
82
83#[derive(Error, Debug, PartialEq)]
84pub enum BlobIdParseError {
85 #[error("cannot contain uppercase hex characters")]
86 CannotContainUppercase,
87
88 #[error("invalid length, expected {} hex bytes, got {}", crate::types::BLOB_ID_SIZE, .0)]
89 InvalidLength(usize),
90
91 #[error("invalid hex")]
92 FromHexError(#[from] hex::FromHexError),
93}
94
95#[derive(Error, Debug)]
96pub enum BlobIdFromSliceError {
97 #[error("invalid length, expected {} bytes, got {}", crate::types::BLOB_ID_SIZE, .0)]
98 InvalidLength(usize),
99}
100
101#[derive(Error, Debug)]
102pub enum ResolutionContextError {
103 #[error("bytes was neither empty nor a valid BlobId")]
104 InvalidBlobId(#[source] BlobIdFromSliceError),
105}
106
107#[derive(Error, Debug)]
108pub enum MirrorConfigError {
109 #[error("Mirror URLs must have schemes")]
110 MirrorUrlMissingScheme,
111
112 #[error("Blob mirror URLs must have schemes")]
113 BlobMirrorUrlMissingScheme,
114}
115
116#[derive(Error, Debug)]
117pub enum RepositoryParseError {
118 #[error("unsupported key type")]
119 UnsupportedKeyType,
120
121 #[error("missing required field repo_url")]
122 RepoUrlMissing,
123
124 #[error("missing required field mirror_url")]
125 MirrorUrlMissing,
126
127 #[error("missing required field subscribe")]
128 SubscribeMissing,
129
130 #[error("invalid repository url")]
131 InvalidRepoUrl(#[source] fuchsia_url::ParseError),
132
133 #[error("invalid update package url")]
134 InvalidUpdatePackageUrl(#[source] fuchsia_url::ParseError),
135
136 #[error("invalid root version: {0}")]
137 InvalidRootVersion(u32),
138
139 #[error("invalid root threshold: {0}")]
140 InvalidRootThreshold(u32),
141
142 #[error("invalid uri")]
143 InvalidUri(#[from] http::uri::InvalidUri),
144
145 #[error("invalid config")]
146 MirrorConfig(#[from] MirrorConfigError),
147}
148
149#[derive(Error, Debug)]
150pub enum RepositoryUrlParseError {
151 #[error("invalid repository url")]
152 InvalidRepoUrl(#[source] fuchsia_url::ParseError),
153}
154
155#[derive(Debug, thiserror::Error)]
156pub enum CupMissingField {
157 #[error("CupData response field")]
158 Response,
159 #[error("CupData request field")]
160 Request,
161 #[error("CupData key_id field")]
162 KeyId,
163 #[error("CupData nonce field")]
164 Nonce,
165 #[error("CupData signature field")]
166 Signature,
167}