Skip to content

Commit

Permalink
move error kind up in module
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Oct 28, 2024
1 parent caae6bb commit 354f7b2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 74 deletions.
4 changes: 2 additions & 2 deletions crates/core/src/commands/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ impl KeepOptions {
) -> RusticResult<Vec<ForgetSnapshot>> {
if !self.is_valid() {
return Err(RusticError::new(
ErrorKind::Io,
"No valid keep options specified, please make sure to specify at least one keep-* option.",
ErrorKind::InvalidInput,
"Invalid keep options specified, please make sure to specify at least one keep-* option.",
));
}

Expand Down
146 changes: 74 additions & 72 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,80 @@ pub(crate) mod constants {
/// Result type that is being returned from methods that can fail and thus have [`RusticError`]s.
pub type RusticResult<T, E = Box<RusticError>> = Result<T, E>;

/// Severity of an error, ranging from informational to fatal.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Severity {
/// Informational
Info,

/// Warning
Warning,

/// Error
Error,

/// Fatal
Fatal,
}

/// Status of an error, indicating whether it is permanent, temporary, or persistent.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Status {
/// Permanent, may not be retried
Permanent,

/// Temporary, may be retried
Temporary,

/// Persistent, may be retried, but may not succeed
Persistent,
}

/// [`ErrorKind`] describes the errors that can happen while executing a high-level command.
///
/// This is a non-exhaustive enum, so additional variants may be added in future. It is
/// recommended to match against the wildcard `_` instead of listing all possible variants,
/// to avoid problems when new variants are added.
#[non_exhaustive]
#[derive(thiserror::Error, Debug, displaydoc::Display)]
pub enum ErrorKind {
/// Append-only Error
AppendOnly,
/// Backend Error
Backend,
/// Command Error
Command,
/// Config Error
Config,
/// Cryptography Error
Cryptography,
/// External Command Error
ExternalCommand,
/// Internal Error
// Blob, Pack, Index, Tree Errors
// Compression, Parsing, Multithreading etc.
// These are deep errors that are not expected to be handled by the user.
Internal,
/// Invalid Input Error
InvalidInput,
/// Input/Output Error
Io,
/// Key Error
Key,
/// Missing Input Error
MissingInput,
/// Password Error
Password,
/// Repository Error
Repository,
/// Unsupported Feature Error
Unsupported,
/// Verification Error
Verification,
/// Virtual File System Error
Vfs,
}

#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
/// Errors that can result from rustic.
Expand Down Expand Up @@ -375,75 +449,3 @@ impl RusticError {
})
}
}

/// Severity of an error, ranging from informational to fatal.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Severity {
/// Informational
Info,

/// Warning
Warning,

/// Error
Error,

/// Fatal
Fatal,
}

/// Status of an error, indicating whether it is permanent, temporary, or persistent.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Status {
/// Permanent, may not be retried
Permanent,

/// Temporary, may be retried
Temporary,

/// Persistent, may be retried, but may not succeed
Persistent,
}

/// [`ErrorKind`] describes the errors that can happen while executing a high-level command.
///
/// This is a non-exhaustive enum, so additional variants may be added in future. It is
/// recommended to match against the wildcard `_` instead of listing all possible variants,
/// to avoid problems when new variants are added.
#[non_exhaustive]
#[derive(thiserror::Error, Debug, displaydoc::Display)]
pub enum ErrorKind {
/// Append-only mode is enabled
AppendOnly,
/// Backend Error
Backend,
/// Command Error
Command,
/// Config Error
Config,
/// Crypto Error
Cryptography,
/// External Command Error
ExternalCommand,
/// Blob, Pack, Index or Tree Error
// These are deep errors that are not expected to be handled by the user.
Internal,
/// Invalid Input Error
InvalidInput,
/// Input/Output Error
Io,
/// Key Error
Key,
/// Missing Input Error
MissingInput,
/// Password Error
Password,
/// Repository Error
Repository,
/// Something is not supported
Unsupported,
/// Verification Error
Verification,
/// Virtual File System Error
Vfs,
}

0 comments on commit 354f7b2

Please sign in to comment.