-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: break up ExtensionError into method-specific error types (#3740)
- Loading branch information
1 parent
41378d5
commit 36c7352
Showing
12 changed files
with
263 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,165 @@ | ||
#![allow(dead_code)] | ||
use crate::error::structured_file::StructuredFileError; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ExtensionError { | ||
// errors related to extension directory management | ||
#[error("Cannot find cache directory")] | ||
FindCacheDirectoryFailed(#[source] crate::error::cache::CacheError), | ||
#[error("Failed to load extension manifest")] | ||
pub struct LoadExtensionManifestError(#[from] StructuredFileError); | ||
|
||
#[error("Cannot get extensions directory")] | ||
EnsureExtensionDirExistsFailed(#[source] crate::error::fs::FsError), | ||
#[derive(Error, Debug)] | ||
pub enum ConvertExtensionIntoClapCommandError { | ||
#[error(transparent)] | ||
LoadExtensionManifest(#[from] LoadExtensionManifestError), | ||
|
||
#[error("Extension directory '{0}' does not exist.")] | ||
ExtensionDirDoesNotExist(std::path::PathBuf), | ||
#[error(transparent)] | ||
ListInstalledExtensionsError(#[from] ListInstalledExtensionsError), | ||
|
||
#[error("Extension '{0}' not installed.")] | ||
ExtensionNotInstalled(String), | ||
#[error(transparent)] | ||
ConvertExtensionSubcommandIntoClapCommandError( | ||
#[from] ConvertExtensionSubcommandIntoClapCommandError, | ||
), | ||
} | ||
|
||
// errors related to installing extensions | ||
#[error("Extension '{0}' is already installed.")] | ||
ExtensionAlreadyInstalled(String), | ||
#[derive(Error, Debug)] | ||
pub enum ConvertExtensionSubcommandIntoClapCommandError { | ||
#[error(transparent)] | ||
ConvertExtensionSubcommandIntoClapArgError(#[from] ConvertExtensionSubcommandIntoClapArgError), | ||
} | ||
|
||
#[error("Extension '{0}' cannot be installed because it conflicts with an existing command. Consider using '--install-as' flag to install this extension under different name.")] | ||
CommandAlreadyExists(String), | ||
#[derive(Error, Debug)] | ||
pub enum ListInstalledExtensionsError { | ||
#[error(transparent)] | ||
ExtensionsDirectoryIsNotReadable(#[from] crate::error::fs::FsError), | ||
} | ||
|
||
#[error("Cannot fetch compatibility.json from '{0}'")] | ||
CompatibilityMatrixFetchError(String, #[source] reqwest::Error), | ||
#[derive(Error, Debug)] | ||
pub enum ConvertExtensionSubcommandIntoClapArgError { | ||
#[error("Extension's subcommand argument '{0}' is missing description.")] | ||
ExtensionSubcommandArgMissingDescription(String), | ||
} | ||
|
||
#[error("Cannot parse compatibility.json")] | ||
MalformedCompatibilityMatrix(#[source] reqwest::Error), | ||
#[derive(Error, Debug)] | ||
pub enum RunExtensionError { | ||
#[error("Invalid extension name '{0:?}'.")] | ||
InvalidExtensionName(std::ffi::OsString), | ||
|
||
#[error("Cannot parse compatibility.json due to malformed semver '{0}'")] | ||
MalformedVersionsEntryForExtensionInCompatibilityMatrix(String, #[source] semver::Error), | ||
#[error("Cannot find cache directory")] | ||
FindCacheDirectoryFailed(#[source] crate::error::cache::CacheError), | ||
|
||
#[error("Cannot find compatible extension for dfx version '{1}': compatibility.json (downloaded from '{0}') has empty list of extension versions.")] | ||
ListOfVersionsForExtensionIsEmpty(String, semver::Version), | ||
#[error("Failed to run extension '{0}'")] | ||
FailedToLaunchExtension(String, #[source] std::io::Error), | ||
|
||
#[error("Cannot parse extension manifest URL '{0}'")] | ||
MalformedExtensionDownloadUrl(String, #[source] url::ParseError), | ||
#[error("Extension '{0}' never finished")] | ||
ExtensionNeverFinishedExecuting(String, #[source] std::io::Error), | ||
|
||
#[error("DFX version '{0}' is not supported.")] | ||
DfxVersionNotFoundInCompatibilityJson(semver::Version), | ||
#[error("Extension terminated by signal.")] | ||
ExtensionExecutionTerminatedViaSignal, | ||
|
||
#[error("Extension '{0}' (version '{1}') not found for DFX version {2}.")] | ||
ExtensionVersionNotFoundInRepository(String, semver::Version, String), | ||
#[error("Extension exited with non-zero status code '{0}'.")] | ||
ExtensionExitedWithNonZeroStatus(i32), | ||
|
||
#[error(transparent)] | ||
GetExtensionBinaryError(#[from] GetExtensionBinaryError), | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum GetExtensionBinaryError { | ||
#[error("Extension '{0}' not installed.")] | ||
ExtensionNotInstalled(String), | ||
|
||
#[error("Cannot find extension binary at '{0}'.")] | ||
ExtensionBinaryDoesNotExist(std::path::PathBuf), | ||
|
||
#[error("Extension binary at {0} is not an executable file.")] | ||
ExtensionBinaryIsNotAFile(std::path::PathBuf), | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum NewExtensionManagerError { | ||
#[error("Cannot find cache directory")] | ||
FindCacheDirectoryFailed(#[source] crate::error::cache::CacheError), | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum DownloadAndInstallExtensionToTempdirError { | ||
#[error("Downloading extension from '{0}' failed")] | ||
ExtensionDownloadFailed(url::Url, #[source] reqwest::Error), | ||
|
||
#[error("Cannot decompress extension archive (downloaded from: '{0}')")] | ||
DecompressFailed(url::Url, #[source] std::io::Error), | ||
#[error("Cannot get extensions directory")] | ||
EnsureExtensionDirExistsFailed(#[source] crate::error::fs::FsError), | ||
|
||
#[error("Cannot create temporary directory at '{0}'")] | ||
CreateTemporaryDirectoryFailed(std::path::PathBuf, #[source] std::io::Error), | ||
|
||
#[error("Cannot decompress extension archive (downloaded from: '{0}')")] | ||
DecompressFailed(url::Url, #[source] std::io::Error), | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum InstallExtensionError { | ||
#[error("Extension '{0}' is already installed.")] | ||
ExtensionAlreadyInstalled(String), | ||
|
||
#[error(transparent)] | ||
Io(#[from] crate::error::fs::FsError), | ||
GetExtensionArchiveName(#[from] GetExtensionArchiveNameError), | ||
|
||
#[error("Platform '{0}' is not supported.")] | ||
PlatformNotSupported(String), | ||
#[error(transparent)] | ||
FindLatestExtensionCompatibleVersion(#[from] FindLatestExtensionCompatibleVersionError), | ||
|
||
// errors related to uninstalling extensions | ||
#[error("Cannot uninstall extension")] | ||
InsufficientPermissionsToDeleteExtensionDirectory(#[source] crate::error::fs::FsError), | ||
#[error(transparent)] | ||
GetExtensionDownloadUrl(#[from] GetExtensionDownloadUrlError), | ||
|
||
// errors related to listing extensions | ||
#[error("Cannot list extensions")] | ||
ExtensionsDirectoryIsNotReadable(#[source] crate::error::fs::FsError), | ||
#[error(transparent)] | ||
DownloadAndInstallExtensionToTempdir(#[from] DownloadAndInstallExtensionToTempdirError), | ||
|
||
#[error("Cannot load extension manifest")] | ||
LoadExtensionManifestFailed(#[source] crate::error::structured_file::StructuredFileError), | ||
#[error(transparent)] | ||
FinalizeInstallation(#[from] FinalizeInstallationError), | ||
} | ||
|
||
// errors related to executing extensions | ||
#[error("Invalid extension name '{0:?}'.")] | ||
InvalidExtensionName(std::ffi::OsString), | ||
#[derive(Error, Debug)] | ||
pub enum GetExtensionArchiveNameError { | ||
#[error("Platform '{0}' is not supported.")] | ||
PlatformNotSupported(String), | ||
} | ||
|
||
#[error("Extension's subcommand argument '{0}' is missing description.")] | ||
ExtensionSubcommandArgMissingDescription(String), | ||
#[derive(Error, Debug)] | ||
pub enum FindLatestExtensionCompatibleVersionError { | ||
#[error("DFX version '{0}' is not supported.")] | ||
DfxVersionNotFoundInCompatibilityJson(semver::Version), | ||
|
||
#[error("Cannot find extension binary at '{0}'.")] | ||
ExtensionBinaryDoesNotExist(std::path::PathBuf), | ||
#[error("Extension '{0}' (version '{1}') not found for DFX version {2}.")] | ||
ExtensionVersionNotFoundInRepository(String, semver::Version, String), | ||
|
||
#[error("Extension binary at {0} is not an executable file.")] | ||
ExtensionBinaryIsNotAFile(std::path::PathBuf), | ||
#[error("Cannot parse compatibility.json due to malformed semver '{0}'")] | ||
MalformedVersionsEntryForExtensionInCompatibilityMatrix(String, #[source] semver::Error), | ||
|
||
#[error("Failed to run extension '{0}'")] | ||
FailedToLaunchExtension(String, #[source] std::io::Error), | ||
#[error("Cannot find compatible extension for dfx version '{1}': compatibility.json (downloaded from '{0}') has empty list of extension versions.")] | ||
ListOfVersionsForExtensionIsEmpty(String, semver::Version), | ||
|
||
#[error("Extension '{0}' never finished")] | ||
ExtensionNeverFinishedExecuting(String, #[source] std::io::Error), | ||
#[error(transparent)] | ||
FetchExtensionCompatibilityMatrix(#[from] FetchExtensionCompatibilityMatrixError), | ||
} | ||
|
||
#[error("Extension terminated by signal.")] | ||
ExtensionExecutionTerminatedViaSignal, | ||
#[derive(Error, Debug)] | ||
#[error("Failed to parse extension manifest URL '{url}'")] | ||
pub struct GetExtensionDownloadUrlError { | ||
pub url: String, | ||
pub source: url::ParseError, | ||
} | ||
|
||
#[error("Extension exited with non-zero status code '{0}'.")] | ||
ExtensionExitedWithNonZeroStatus(i32), | ||
#[derive(Error, Debug)] | ||
#[error(transparent)] | ||
pub struct FinalizeInstallationError(#[from] crate::error::fs::FsError); | ||
|
||
#[derive(Error, Debug)] | ||
pub enum FetchExtensionCompatibilityMatrixError { | ||
#[error("Cannot fetch compatibility.json from '{0}'")] | ||
CompatibilityMatrixFetchError(String, #[source] reqwest::Error), | ||
|
||
#[error("Cannot parse compatibility.json")] | ||
MalformedCompatibilityMatrix(#[source] reqwest::Error), | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
#[error(transparent)] | ||
pub struct UninstallExtensionError(#[from] crate::error::fs::FsError); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.