-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom error types for all errors generated in the library. Signed-off-by: José Guilherme Vanz <[email protected]>
- Loading branch information
Showing
16 changed files
with
414 additions
and
187 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum FetcherErrors { | ||
#[error("Fail to interact with OCI registry: {0}")] | ||
OCIRegistryError(#[from] oci_distribution::errors::OciDistributionError), | ||
#[error("Invalid destination format")] | ||
InvalidDestinationError, | ||
|
||
#[error("cannot retrieve path from uri: {0}")] | ||
InvalidFilePathError(String), | ||
#[error("invalid wasm file")] | ||
InvalidWasmFileError, | ||
#[error("wasm module cannot be save to {0:?}: {1}")] | ||
CannotWriteWasmModuleFile(String, #[source] std::io::Error), | ||
|
||
#[error(transparent)] | ||
PolicyError(#[from] crate::policy::DigestError), | ||
#[error(transparent)] | ||
VerifyError(#[from] VerifyErrors), | ||
#[error(transparent)] | ||
RegistryError(#[from] RegistryErrors), | ||
#[error(transparent)] | ||
UrlParserError(#[from] url::ParseError), | ||
#[error(transparent)] | ||
SourceError(#[from] SourceErrors), | ||
#[error(transparent)] | ||
StoreError(#[from] StoreErrors), | ||
#[error(transparent)] | ||
InvalidURLError(#[from] InvalidURLError), | ||
#[error(transparent)] | ||
CannotCreateStoragePathError(#[from] CannotCreateStoragePathError), | ||
} | ||
|
||
//#[derive(Error, Debug)] | ||
//pub enum InnerErrors{ | ||
// #[error("invalid URL: {0}")] | ||
// InvalidURLError(String), | ||
// #[error("Fail to interact with OCI registry: {0}")] | ||
// OCIRegistryError(#[from] oci_distribution::errors::OciDistributionError), | ||
// #[error("Invalid OCI image reference: {0}")] | ||
// InvalidOCIImageReferenceError(#[from] oci_distribution::ParseError), | ||
// #[error("could not pull policy {0}: empty layers")] | ||
// EmptyLayersError(String), | ||
// //#[error("Invalid certificate: {0}")] | ||
// //InvalidCertificateError(String), | ||
// //#[error("Cannot read certificate from file: {0}")] | ||
// //CannotReadCertificateError(#[from] std::io::Error), | ||
//} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
#[error("{0}")] | ||
pub struct FailedToParseYamlDataError(#[from] pub serde_yaml::Error); | ||
|
||
#[derive(Error, Debug)] | ||
pub enum SourceErrors { | ||
#[error(transparent)] | ||
InvalidURLError(#[from] InvalidURLError), | ||
#[error("Fail to interact with OCI registry: {0}")] | ||
OCIRegistryError(#[from] oci_distribution::errors::OciDistributionError), | ||
#[error("Invalid OCI image reference: {0}")] | ||
InvalidOCIImageReferenceError(#[from] oci_distribution::ParseError), | ||
#[error("could not pull policy {0}: empty layers")] | ||
EmptyLayersError(String), | ||
#[error("Invalid certificate: {0}")] | ||
InvalidCertificateError(String), | ||
#[error("Cannot read certificate from file: {0}")] | ||
CannotReadCertificateError(#[from] std::io::Error), | ||
#[error(transparent)] | ||
FailedToParseYamlDataError(#[from] FailedToParseYamlDataError), | ||
#[error("failed to create the http client: {0}")] | ||
FailedToCreateHttpClientError(#[from] reqwest::Error), | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
#[error("invalid URL: {0}")] | ||
pub struct CannotCreateStoragePathError(#[from] pub std::io::Error); | ||
|
||
#[derive(Error, Debug)] | ||
pub enum StoreErrors { | ||
#[error(transparent)] | ||
UrlParserError(#[from] url::ParseError), | ||
#[error("faild to read verification file: {0}")] | ||
VerificationFileReadError(#[from] std::io::Error), | ||
#[error("cannot read policy in local storage: {0}")] | ||
FailedToReadPolicyInLocalStorageError(#[from] walkdir::Error), | ||
#[error(transparent)] | ||
PolicyStoragePathError(#[from] std::path::StripPrefixError), | ||
#[error("unknown scheme: {0}")] | ||
UnknownSchemeError(String), | ||
#[error("multiple policies found with the same prefix: {0}")] | ||
MultiplePoliciesFoundError(String), | ||
#[error(transparent)] | ||
DigestErrors(#[from] crate::policy::DigestError), | ||
#[error(transparent)] | ||
CannotCreateStoragePathError(#[from] CannotCreateStoragePathError), | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
#[error("invalid URL: {0}")] | ||
pub struct InvalidURLError(pub String); | ||
|
||
#[derive(Error, Debug)] | ||
pub enum RegistryErrors { | ||
#[error("Fail to interact with OCI registry: {0}")] | ||
OCIRegistryError(#[from] oci_distribution::errors::OciDistributionError), | ||
#[error("Invalid OCI image reference: {0}")] | ||
InvalidOCIImageReferenceError(#[from] oci_distribution::ParseError), | ||
#[error("{0}")] | ||
BuildImmutableReferenceError(String), | ||
#[error("Invalid destination format")] | ||
InvalidDestinationError, | ||
#[error("{0}")] | ||
OtherError(String), | ||
#[error(transparent)] | ||
UrlParserError(#[from] url::ParseError), | ||
#[error(transparent)] | ||
DigestErrors(#[from] crate::policy::DigestError), | ||
#[error(transparent)] | ||
InvalidURLError(#[from] InvalidURLError), | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum VerifyErrors { | ||
#[error("faild to read verification file: {0}")] | ||
VerificationFileReadError(#[from] std::io::Error), | ||
#[error("{0}")] | ||
ChecksumVerificationError(String), | ||
#[error("{0}")] | ||
ImageVerificationError(String), | ||
#[error("{0}")] | ||
InvalidVerifyFileError(String), | ||
#[error("Verification only works with OCI images: Not a valid oci image: {0}")] | ||
InvalidOCIImageReferenceError(#[from] oci_distribution::ParseError), | ||
#[error("key verification failure: {0} ")] | ||
KeyVerificationError(#[source] sigstore::errors::SigstoreError), | ||
#[error("Policy cannot be verified, local wasm file doesn't exist: {0}")] | ||
MissingWasmFileError(String), | ||
#[error("failed to get image trusted layers: {0}")] | ||
FailedToFetchTrustedLayersError(#[from] sigstore::errors::SigstoreError), | ||
#[error(transparent)] | ||
DigestErrors(#[from] crate::policy::DigestError), | ||
#[error(transparent)] | ||
RegistryError(#[from] RegistryErrors), | ||
#[error("{0}")] | ||
GithubUrlParserError(String), | ||
#[error(transparent)] | ||
FailedToParseYamlDataError(#[from] FailedToParseYamlDataError), | ||
} |
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
Oops, something went wrong.