vach/global/error.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
use std::{error, io, sync::Arc};
use thiserror::Error;
/// Internal `Result` type alias used by `vach`. Basically equal to: `Result<T, InternalError>`
pub type InternalResult<T = ()> = Result<T, InternalError>;
/// All errors manifestable within `vach` collected into a neat enum
#[derive(Debug, Error)]
pub enum InternalError {
/// Generic all encompassing error
#[error("[VachError::GenericError] {0}")]
OtherError(Box<dyn error::Error + Send + Sync>),
/// Produced when a cargo feature isn't available for a certain action: eg trying to decompress without the compression feature
#[error("[VachError::MissingFeatureError] Unable to continue with operation, the cargo feature ({0}) is missing")]
MissingFeatureError(&'static str),
/// An error that is returned when either a [Keypair](crate::crypto::Keypair), Signature, [PublicKey](crate::crypto::PublicKey) or [SecretKey](crate::crypto::SecretKey) fails to deserialize.
#[error("[VachError::ParseError] {0}")]
ParseError(String),
/// A thin wrapper over [io::Error](std::io::Error), captures all IO errors
#[error("[VachError::IOError] {0}")]
IOError(#[from] io::Error),
/// Thrown when the archive finds an invalid MAGIC sequence in the given source, hinting at corruption or possible incompatibility with the given source
/// You can customize the MAGIC in the [`Builder`](crate::builder::BuilderConfig) and use in the the [`ArchiveConfig`](crate::archive::ArchiveConfig)
#[error("[VachError::ValidationError] Invalid magic found in Header, possible incompatibility with given source. Magic found {0:?}")]
MalformedArchiveSource([u8; crate::MAGIC_LENGTH]),
/// Thrown by `Archive::fetch(---)` when a given resource is not found
#[error("[VachError::MissingResourceError] Resource not found: {0}")]
MissingResourceError(String),
/// Thrown when a leaf with an identical ID to a queued leaf is add with the `Builder::add(---)` functions
#[error("[VachError::LeafAppendError] A leaf with the ID: {0} already exists. Consider changing the ID to prevent collisions")]
LeafAppendError(Arc<str>),
/// Thrown when no `Keypair` is provided and an encrypted [Leaf](crate::builder::Leaf) is encountered
#[error("[VachError::NoKeypairError] Unable to continue with cryptographic operation, as no keypair was supplied")]
NoKeypairError,
/// Thrown when decryption or encryption fails
#[cfg(feature = "crypto")]
#[error("[VachError::CryptoError] {0}")]
CryptoError(aes_gcm::Error),
/// Thrown when an attempt is made to set a bit within the first four bits(restricted) of a [`Flags`](crate::prelude::Flags) instance
#[error("[VachError::RestrictedFlagAccessError] Tried to set reserved bit(s)!")]
RestrictedFlagAccessError,
/// When a [`Leaf`](crate::builder::Leaf) has an ID that is longer than `crate::MAX_ID_LENGTH`, contains the overflowing `ID`
#[error("[VachError::IDSizeOverflowError] The maximum size of any ID is: {}. The leaf with ID: {0} has an overflowing ID of length: {}", crate::MAX_ID_LENGTH, .0.len())]
IDSizeOverflowError(String),
/// An error that is thrown when the current archive attempts to load an incompatible version, contains the incompatible version
#[error("The provided archive source has version: {}. While the current implementation has a spec-version: {}. The provided source is incompatible!", .0, crate::VERSION)]
IncompatibleArchiveVersionError(u16),
/// Errors thrown during compression or decompression
#[error("[VachError::CompressorDecompressorError]: {0}")]
#[cfg(feature = "compression")]
DeCompressionError(#[from] lz4_flex::frame::Error),
}