1#![allow(dead_code)]
2
3use crate::error::cache::{EnsureCacheVersionsDirError, GetCacheRootError};
4use crate::error::fs::{
5 EnsureDirExistsError, ReadDirError, RemoveDirectoryAndContentsError, RenameError,
6 SetPermissionsError,
7};
8use crate::error::structured_file::StructuredFileError;
9use semver::Version;
10use thiserror::Error;
11
12#[derive(Error, Debug)]
13#[error("Failed to load extension manifest")]
14pub struct LoadExtensionManifestError(#[from] StructuredFileError);
15
16#[derive(Error, Debug)]
17pub enum ConvertExtensionIntoClapCommandError {
18 #[error(transparent)]
19 LoadExtensionManifest(#[from] LoadExtensionManifestError),
20
21 #[error(transparent)]
22 ListInstalledExtensionsError(#[from] ListInstalledExtensionsError),
23
24 #[error(transparent)]
25 ConvertExtensionSubcommandIntoClapCommandError(
26 #[from] ConvertExtensionSubcommandIntoClapCommandError,
27 ),
28}
29
30#[derive(Error, Debug)]
31pub enum ConvertExtensionSubcommandIntoClapCommandError {
32 #[error(transparent)]
33 ConvertExtensionSubcommandIntoClapArgError(#[from] ConvertExtensionSubcommandIntoClapArgError),
34}
35
36#[derive(Error, Debug)]
37pub enum ListAvailableExtensionsError {
38 #[error(transparent)]
39 FetchCatalog(#[from] FetchCatalogError),
40}
41
42#[derive(Error, Debug)]
43pub enum ListInstalledExtensionsError {
44 #[error(transparent)]
45 ExtensionsDirectoryIsNotReadable(#[from] ReadDirError),
46}
47
48#[derive(Error, Debug)]
49pub enum LoadExtensionManifestsError {
50 #[error(transparent)]
51 ListInstalledExtensions(#[from] ListInstalledExtensionsError),
52
53 #[error(transparent)]
54 LoadExtensionManifest(#[from] LoadExtensionManifestError),
55}
56
57#[derive(Error, Debug)]
58pub enum ConvertExtensionSubcommandIntoClapArgError {
59 #[error("Extension's subcommand argument '{0}' is missing description.")]
60 ExtensionSubcommandArgMissingDescription(String),
61}
62
63#[derive(Error, Debug)]
64pub enum RunExtensionError {
65 #[error("Invalid extension name '{0:?}'.")]
66 InvalidExtensionName(std::ffi::OsString),
67
68 #[error("Cannot find cache directory")]
69 FindCacheDirectoryFailed(#[from] EnsureCacheVersionsDirError),
70
71 #[error("Failed to run extension '{0}'")]
72 FailedToLaunchExtension(String, #[source] std::io::Error),
73
74 #[error("Extension '{0}' never finished")]
75 ExtensionNeverFinishedExecuting(String, #[source] std::io::Error),
76
77 #[error("Extension terminated by signal.")]
78 ExtensionExecutionTerminatedViaSignal,
79
80 #[error("Extension exited with non-zero status code '{0}'.")]
81 ExtensionExitedWithNonZeroStatus(i32),
82
83 #[error(transparent)]
84 GetExtensionBinaryError(#[from] GetExtensionBinaryError),
85}
86
87#[derive(Error, Debug)]
88pub enum GetExtensionBinaryError {
89 #[error("Extension '{0}' not installed.")]
90 ExtensionNotInstalled(String),
91
92 #[error("Cannot find extension binary at '{0}'.")]
93 ExtensionBinaryDoesNotExist(std::path::PathBuf),
94
95 #[error("Extension binary at {0} is not an executable file.")]
96 ExtensionBinaryIsNotAFile(std::path::PathBuf),
97}
98
99#[derive(Error, Debug)]
100pub enum NewExtensionManagerError {
101 #[error("Cannot find cache directory")]
102 FindCacheDirectoryFailed(#[from] GetCacheRootError),
103}
104
105#[derive(Error, Debug)]
106pub enum DownloadAndInstallExtensionToTempdirError {
107 #[error(transparent)]
108 ExtensionDownloadFailed(reqwest::Error),
109
110 #[error(transparent)]
111 EnsureExtensionDirExistsFailed(#[from] EnsureDirExistsError),
112
113 #[error("Cannot create temporary directory at '{0}'")]
114 CreateTemporaryDirectoryFailed(std::path::PathBuf, #[source] std::io::Error),
115
116 #[error("Cannot decompress extension archive (downloaded from: '{0}')")]
117 DecompressFailed(url::Url, #[source] std::io::Error),
118}
119
120#[derive(Error, Debug)]
121pub enum InstallExtensionError {
122 #[error("extension '{0}' not found in catalog")]
123 ExtensionNotFound(String),
124
125 #[error("Extension '{0}' is already installed at version {1}.")]
126 OtherVersionAlreadyInstalled(String, Version),
127
128 #[error(transparent)]
129 FetchCatalog(#[from] FetchCatalogError),
130
131 #[error(transparent)]
132 GetExtensionArchiveName(#[from] GetExtensionArchiveNameError),
133
134 #[error(transparent)]
135 GetHighestCompatibleVersion(#[from] GetHighestCompatibleVersionError),
136
137 #[error(transparent)]
138 GetExtensionDownloadUrl(#[from] GetExtensionDownloadUrlError),
139
140 #[error(transparent)]
141 GetExtensionManifest(#[from] GetExtensionManifestError),
142
143 #[error(transparent)]
144 DownloadAndInstallExtensionToTempdir(#[from] DownloadAndInstallExtensionToTempdirError),
145
146 #[error(transparent)]
147 FinalizeInstallation(#[from] FinalizeInstallationError),
148
149 #[error(transparent)]
150 LoadManifest(#[from] LoadExtensionManifestError),
151}
152
153#[derive(Error, Debug)]
154pub enum GetExtensionArchiveNameError {
155 #[error("Platform '{0}' is not supported.")]
156 PlatformNotSupported(String),
157}
158
159#[derive(Error, Debug)]
160pub enum GetHighestCompatibleVersionError {
161 #[error(transparent)]
162 GetDependencies(#[from] GetDependenciesError),
163
164 #[error("No compatible version found.")]
165 NoCompatibleVersionFound(),
166
167 #[error(transparent)]
168 DfxOnlyPossibleDependency(#[from] DfxOnlySupportedDependency),
169}
170
171#[derive(Error, Debug)]
172pub enum GetDependenciesError {
173 #[error(transparent)]
174 ParseUrl(#[from] url::ParseError),
175
176 #[error(transparent)]
177 Get(reqwest::Error),
178
179 #[error(transparent)]
180 ParseJson(reqwest::Error),
181}
182
183#[derive(Error, Debug)]
184pub enum GetExtensionManifestError {
185 #[error(transparent)]
186 Get(reqwest::Error),
187
188 #[error(transparent)]
189 ParseJson(reqwest::Error),
190}
191
192#[derive(Error, Debug)]
193#[error("'dfx' is the only supported dependency")]
194pub struct DfxOnlySupportedDependency;
195
196#[derive(Error, Debug)]
197#[error("Failed to parse extension manifest URL '{url}'")]
198pub struct GetExtensionDownloadUrlError {
199 pub url: String,
200 pub source: url::ParseError,
201}
202
203#[derive(Error, Debug)]
204pub enum GetTopLevelDirectoryError {
205 #[error(transparent)]
206 ReadDir(#[from] ReadDirError),
207
208 #[error("No top-level directory found in archive")]
209 NoTopLevelDirectoryEntry,
210
211 #[error("Cannot read directory entry")]
212 ReadDirEntry(#[source] std::io::Error),
213}
214
215#[derive(Error, Debug)]
216#[error(transparent)]
217pub enum FinalizeInstallationError {
218 #[error(transparent)]
219 GetTopLevelDirectory(#[from] GetTopLevelDirectoryError),
220
221 #[error(transparent)]
222 LoadExtensionManifest(#[from] LoadExtensionManifestError),
223
224 #[error(transparent)]
225 Rename(#[from] RenameError),
226
227 #[error(transparent)]
228 SetPermissions(#[from] SetPermissionsError),
229}
230
231#[derive(Error, Debug)]
232pub enum FetchExtensionCompatibilityMatrixError {
233 #[error("Cannot fetch compatibility.json from '{0}'")]
234 CompatibilityMatrixFetchError(String, #[source] reqwest::Error),
235
236 #[error("Cannot parse compatibility.json")]
237 MalformedCompatibilityMatrix(#[source] reqwest::Error),
238}
239
240#[derive(Error, Debug)]
241#[error(transparent)]
242pub struct UninstallExtensionError(#[from] RemoveDirectoryAndContentsError);
243
244#[derive(Error, Debug)]
245pub enum FetchCatalogError {
246 #[error(transparent)]
247 ParseUrl(#[from] url::ParseError),
248
249 #[error(transparent)]
250 Get(reqwest::Error),
251
252 #[error(transparent)]
253 ParseJson(reqwest::Error),
254}