diff --git a/crates/core/src/archiver.rs b/crates/core/src/archiver.rs index 337c5465..420f8d52 100644 --- a/crates/core/src/archiver.rs +++ b/crates/core/src/archiver.rs @@ -25,17 +25,9 @@ use crate::{ Progress, }; -/// [`ArchiverErrorKind`] describes the errors that can be returned from the archiver #[derive(thiserror::Error, Debug, displaydoc::Display)] -#[non_exhaustive] -pub enum ArchiverErrorKind { - /// tree stack empty - TreeStackEmpty, - /// couldn't determine size for item in Archiver - CouldNotDetermineSize, -} - -pub(crate) type ArchiverResult = Result; +/// Tree stack empty +pub struct TreeStackEmptyError; /// The `Archiver` is responsible for archiving files and trees. /// It will read the file, chunk it, and write the chunks to the backend. diff --git a/crates/core/src/archiver/parent.rs b/crates/core/src/archiver/parent.rs index e0e15719..f807ce9d 100644 --- a/crates/core/src/archiver/parent.rs +++ b/crates/core/src/archiver/parent.rs @@ -6,7 +6,7 @@ use std::{ use log::warn; use crate::{ - archiver::{tree::TreeType, ArchiverErrorKind, ArchiverResult}, + archiver::{tree::TreeType, TreeStackEmptyError}, backend::{decrypt::DecryptReadBackend, node::Node}, blob::tree::{Tree, TreeId}, index::ReadGlobalIndex, @@ -218,8 +218,8 @@ impl Parent { /// # Errors /// /// * If the tree stack is empty. - fn finish_dir(&mut self) -> ArchiverResult<()> { - let (tree, node_idx) = self.stack.pop().ok_or(ArchiverErrorKind::TreeStackEmpty)?; + fn finish_dir(&mut self) -> Result<(), TreeStackEmptyError> { + let (tree, node_idx) = self.stack.pop().ok_or(TreeStackEmptyError)?; self.tree = tree; self.node_idx = node_idx; @@ -252,7 +252,7 @@ impl Parent { be: &impl DecryptReadBackend, index: &impl ReadGlobalIndex, item: TreeType, - ) -> ArchiverResult> { + ) -> Result, TreeStackEmptyError> { let result = match item { TreeType::NewTree((path, node, tree)) => { let parent_result = self diff --git a/crates/core/src/backend.rs b/crates/core/src/backend.rs index 9f46dd36..67abe40d 100644 --- a/crates/core/src/backend.rs +++ b/crates/core/src/backend.rs @@ -10,7 +10,7 @@ pub(crate) mod node; pub(crate) mod stdin; pub(crate) mod warm_up; -use std::{io::Read, num::TryFromIntError, ops::Deref, path::PathBuf, sync::Arc}; +use std::{io::Read, ops::Deref, path::PathBuf, sync::Arc}; use bytes::Bytes; use enum_map::Enum; @@ -31,64 +31,11 @@ use crate::{ #[derive(thiserror::Error, Debug, displaydoc::Display)] #[non_exhaustive] pub enum BackendErrorKind { - /// backend `{0:?}` is not supported! - BackendNotSupported(String), - /// no suitable id found for `{0}` - NoSuitableIdFound(String), - /// id `{0}` is not unique - IdNotUnique(String), - /// creating data in backend failed - CreatingDataOnBackendFailed, - /// writing bytes to backend failed - WritingBytesToBackendFailed, - /// removing data from backend failed - RemovingDataFromBackendFailed, - /// failed to list files on Backend - ListingFilesOnBackendFailed, /// Path is not allowed: `{0:?}` PathNotAllowed(PathBuf), - /// Backend location not convertible: `{location}` - BackendLocationNotConvertible { location: String }, -} - -/// [`CryptBackendErrorKind`] describes the errors that can be returned by a Decryption action in Backends -#[derive(thiserror::Error, Debug, displaydoc::Display)] -#[non_exhaustive] -pub enum CryptBackendErrorKind { - /// decryption not supported for backend - DecryptionNotSupportedForBackend, - /// length of uncompressed data does not match! - LengthOfUncompressedDataDoesNotMatch, - /// failed to read encrypted data during full read - DecryptionInFullReadFailed, - /// failed to read encrypted data during partial read - DecryptionInPartialReadFailed, - /// decrypting from backend failed - DecryptingFromBackendFailed, - /// deserializing from bytes of JSON Text failed: `{0:?}` - DeserializingFromBytesOfJsonTextFailed(serde_json::Error), - /// failed to write data in crypt backend - WritingDataInCryptBackendFailed, - /// failed to list Ids - ListingIdsInDecryptionBackendFailed, - /// writing full hash failed in `CryptBackend` - WritingFullHashFailed, - /// decoding Zstd compressed data failed: `{0:?}` - DecodingZstdCompressedDataFailed(std::io::Error), - /// Serializing to JSON byte vector failed: `{0:?}` - SerializingToJsonByteVectorFailed(serde_json::Error), - /// encrypting data failed - EncryptingDataFailed, - /// Compressing and appending data failed: `{0:?}` - CopyEncodingDataFailed(std::io::Error), - /// conversion for integer failed: `{0:?}` - IntConversionFailed(TryFromIntError), - /// Extra verification failed: After decrypting and decompressing the data changed! - ExtraVerificationFailed, } pub(crate) type BackendResult = Result; -pub(crate) type CryptBackendResult = Result; /// All [`FileType`]s which are located in separated directories pub const ALL_FILE_TYPES: [FileType; 4] = [ diff --git a/crates/core/src/backend/local_destination.rs b/crates/core/src/backend/local_destination.rs index 69627bf2..1166230f 100644 --- a/crates/core/src/backend/local_destination.rs +++ b/crates/core/src/backend/local_destination.rs @@ -299,7 +299,7 @@ impl LocalDestination { /// # Errors /// /// * If the user/group could not be set. - #[allow(clippy::unused_self)] + #[allow(clippy::unused_self, clippy::unnecessary_wraps)] pub(crate) fn set_user_group( &self, _item: impl AsRef, @@ -355,7 +355,7 @@ impl LocalDestination { /// # Errors /// /// * If the uid/gid could not be set. - #[allow(clippy::unused_self)] + #[allow(clippy::unused_self, clippy::unnecessary_wraps)] pub(crate) fn set_uid_gid( &self, _item: impl AsRef, @@ -403,7 +403,7 @@ impl LocalDestination { /// # Errors /// /// * If the permissions could not be set. - #[allow(clippy::unused_self)] + #[allow(clippy::unused_self, clippy::unnecessary_wraps)] pub(crate) fn set_permission( &self, _item: impl AsRef, @@ -456,7 +456,7 @@ impl LocalDestination { /// # Errors /// /// * If the extended attributes could not be set. - #[allow(clippy::unused_self)] + #[allow(clippy::unused_self, clippy::unnecessary_wraps)] pub(crate) fn set_extended_attributes( &self, _item: impl AsRef, @@ -600,6 +600,7 @@ impl LocalDestination { /// # Returns /// /// Ok if the special file was created. + #[allow(clippy::unused_self, clippy::unnecessary_wraps)] pub(crate) fn create_special( &self, _item: impl AsRef, diff --git a/crates/core/src/chunker.rs b/crates/core/src/chunker.rs index 82f775a3..57b4149e 100644 --- a/crates/core/src/chunker.rs +++ b/crates/core/src/chunker.rs @@ -10,14 +10,6 @@ use crate::{ error::{ErrorKind, RusticError, RusticResult}, }; -/// [`PolynomialErrorKind`] describes the errors that can happen while dealing with Polynomials -#[derive(thiserror::Error, Debug, displaydoc::Display)] -#[non_exhaustive] -pub enum PolynomialErrorKind { - /// no suitable polynomial found - NoSuitablePolynomialFound, -} - pub(super) mod constants { /// The Splitmask is used to determine if a chunk is a chunk boundary. pub(super) const SPLITMASK: u64 = (1u64 << 20) - 1; diff --git a/crates/core/src/commands.rs b/crates/core/src/commands.rs index 61c79cf0..e4d15a12 100644 --- a/crates/core/src/commands.rs +++ b/crates/core/src/commands.rs @@ -1,11 +1,5 @@ //! The commands that can be run by the CLI. -use std::{num::TryFromIntError, path::PathBuf}; - -use chrono::OutOfRangeError; - -use crate::{backend::node::NodeType, blob::BlobId, repofile::packfile::PackId, RusticError}; - pub mod backup; /// The `cat` command. pub mod cat; @@ -26,41 +20,3 @@ pub mod repair; pub mod repoinfo; pub mod restore; pub mod snapshots; - -/// [`CommandErrorKind`] describes the errors that can happen while executing a high-level command -#[derive(thiserror::Error, Debug, displaydoc::Display)] -#[non_exhaustive] -pub enum CommandErrorKind { - /// path is no dir: `{0}` - PathIsNoDir(String), - /// used blobs are missing: blob `{0}` doesn't existing - BlobsMissing(BlobId), - /// used pack `{0}`: size does not match! Expected size: `{1}`, real size: `{2}` - PackSizeNotMatching(PackId, u32, u32), - /// used pack `{0}` does not exist! - PackNotExisting(PackId), - /// pack `{0}` got no decision what to do - NoDecision(PackId), - /// Bytesize parser failed: `{0}` - FromByteSizeParser(String), - /// --repack-uncompressed makes no sense for v1 repo! - RepackUncompressedRepoV1, - /// datetime out of range: `{0}` - FromOutOfRangeError(OutOfRangeError), - /// node type `{0:?}` not supported by dump - DumpNotSupported(NodeType), - /// error creating `{0:?}`: `{1:?}` - ErrorCreating(PathBuf, Box), - /// error collecting information for `{0:?}`: `{1:?}` - ErrorCollecting(PathBuf, Box), - /// error setting length for `{0:?}`: `{1:?}` - ErrorSettingLength(PathBuf, Box), - /// Conversion from integer failed: `{0:?}` - ConversionFromIntFailed(TryFromIntError), - /// Specify one of the keep-* options for forget! Please use keep-none to keep no snapshot. - NoKeepOption, - /// Checking the repository failed! - CheckFailed, -} - -pub(crate) type CommandResult = Result; diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs index 08e4fd78..c767e637 100644 --- a/crates/core/src/error.rs +++ b/crates/core/src/error.rs @@ -413,76 +413,4 @@ pub enum ErrorKind { Verification, /// Virtual File System Error Vfs, - // /// The repository password is incorrect. Please try again. - // IncorrectRepositoryPassword, - // /// No repository given. Please use the --repository option. - // NoRepositoryGiven, - // /// No password given. Please use one of the --password-* options. - // NoPasswordGiven, - // /// warm-up command must contain %id! - // NoIDSpecified, - // /// error opening password file `{0:?}` - // OpeningPasswordFileFailed(std::io::Error), - // /// No repository config file found. Is there a repo at `{0}`? - // NoRepositoryConfigFound(String), - // /// More than one repository config file at `{0}`. Aborting. - // MoreThanOneRepositoryConfig(String), - // /// keys from repo and repo-hot do not match for `{0}`. Aborting. - // KeysDontMatchForRepositories(String), - // /// repository is a hot repository!\nPlease use as --repo-hot in combination with the normal repo. Aborting. - // HotRepositoryFlagMissing, - // /// repo-hot is not a hot repository! Aborting. - // IsNotHotRepository, - // /// incorrect password! - // IncorrectPassword, - // /// error running the password command - // PasswordCommandExecutionFailed, - // /// error reading password from command - // ReadingPasswordFromCommandFailed, - // /// running command `{0}`:`{1}` was not successful: `{2}` - // CommandExecutionFailed(String, String, std::io::Error), - // /// running command {0}:{1} returned status: `{2}` - // CommandErrorStatus(String, String, ExitStatus), - // /// error listing the repo config file - // ListingRepositoryConfigFileFailed, - // /// error listing the repo keys - // ListingRepositoryKeysFailed, - // /// error listing the hot repo keys - // ListingHotRepositoryKeysFailed, - // /// error accessing config file - // AccessToConfigFileFailed, - // /// Thread pool build error: `{0:?}` - // FromThreadPoolbilderError(rayon::ThreadPoolBuildError), - // /// reading Password failed: `{0:?}` - // ReadingPasswordFromReaderFailed(std::io::Error), - // /// reading Password from prompt failed: `{0:?}` - // ReadingPasswordFromPromptFailed(std::io::Error), - // /// Config file already exists. Aborting. - // ConfigFileExists, - // /// did not find id `{0}` in index - // IdNotFound(BlobId), - // /// no suitable backend type found - // NoBackendTypeGiven, - // /// Hex decoding error: `{0:?}` - // HexError(hex::FromHexError), } - -// TODO: Possible more general categories for errors for RusticErrorKind (WIP): -// -// - **JSON Parsing Errors**: e.g., `serde_json::Error` -// - **Version Errors**: e.g., `VersionNotSupported`, `CannotDowngrade` -// - **Compression Errors**: e.g., `NoCompressionV1Repo`, `CompressionLevelNotSupported` -// - **Size Errors**: e.g., `SizeTooLarge` -// - **File and Path Errors**: e.g., `ErrorCreating`, `ErrorCollecting`, `ErrorSettingLength` -// - **Thread Pool Errors**: e.g., `rayon::ThreadPoolBuildError` -// - **Conversion Errors**: e.g., `ConversionFromIntFailed` -// - **Permission Errors**: e.g., `NotAllowedWithAppendOnly` -// - **Parsing Errors**: e.g., `shell_words::ParseError` -// - **Cryptographic Errors**: e.g., `DataDecryptionFailed`, `DataEncryptionFailed`, `CryptoKeyTooShort` -// - **Polynomial Errors**: e.g., `NoSuitablePolynomialFound` -// - **File Handling Errors**: e.g., `TransposingOptionResultFailed`, `ConversionFromU64ToUsizeFailed` -// - **ID Processing Errors**: e.g., `HexError` -// - **Repository Errors**: general repository-related errors -// - **Backend Access Errors**: e.g., `BackendNotSupported`, `BackendLoadError`, `NoSuitableIdFound`, `IdNotUnique` -// - **Rclone Errors**: e.g., `NoOutputForRcloneVersion`, `NoStdOutForRclone`, `RCloneExitWithBadStatus` -// - **REST API Errors**: e.g., `NotSupportedForRetry`, `UrlParsingFailed` diff --git a/crates/core/src/index.rs b/crates/core/src/index.rs index 505216b7..65d13940 100644 --- a/crates/core/src/index.rs +++ b/crates/core/src/index.rs @@ -4,7 +4,7 @@ use bytes::Bytes; use derive_more::Constructor; use crate::{ - backend::{decrypt::DecryptReadBackend, CryptBackendErrorKind, FileType}, + backend::{decrypt::DecryptReadBackend, FileType}, blob::{tree::TreeId, BlobId, BlobType, DataId}, error::{ErrorKind, RusticError, RusticResult}, index::binarysorted::{Index, IndexCollector, IndexType}, @@ -18,23 +18,6 @@ use crate::{ pub(crate) mod binarysorted; pub(crate) mod indexer; -/// [`IndexErrorKind`] describes the errors that can be returned by processing Indizes -#[derive(thiserror::Error, Debug, displaydoc::Display)] -#[non_exhaustive] -pub enum IndexErrorKind { - /// blob not found in index - BlobInIndexNotFound, - /// failed to get a blob from the backend - GettingBlobIndexEntryFromBackendFailed, - /// saving `IndexFile` failed - SavingIndexFileFailed { - /// the error that occurred - source: CryptBackendErrorKind, - }, -} - -pub(crate) type IndexResult = Result; - /// An entry in the index #[derive(Debug, Clone, Copy, PartialEq, Eq, Constructor)] pub struct IndexEntry { diff --git a/crates/core/src/repofile/snapshotfile.rs b/crates/core/src/repofile/snapshotfile.rs index 8b779059..e6aef643 100644 --- a/crates/core/src/repofile/snapshotfile.rs +++ b/crates/core/src/repofile/snapshotfile.rs @@ -1249,7 +1249,7 @@ impl PathList { /// # Errors /// /// * no errors can occur here - /// * RusticResult is used for consistency and future compatibility + /// * [`RusticResult`] is used for consistency and future compatibility pub fn from_string(source: &str) -> RusticResult { Ok(Self(vec![source.into()])) } diff --git a/crates/core/src/repository/warm_up.rs b/crates/core/src/repository/warm_up.rs index 05b33d43..ff63529d 100644 --- a/crates/core/src/repository/warm_up.rs +++ b/crates/core/src/repository/warm_up.rs @@ -13,16 +13,6 @@ use crate::{ CommandInput, }; -/// [`WarmupErrorKind`] describes the errors that can be returned from Warmup -#[derive(thiserror::Error, Debug, displaydoc::Display)] -#[non_exhaustive] -pub enum WarmupErrorKind { - /// Error in warm-up command - General, -} - -pub(crate) type WarmupResult = Result; - pub(super) mod constants { /// The maximum number of reader threads to use for warm-up. pub(super) const MAX_READER_THREADS_NUM: usize = 20; diff --git a/crates/core/src/vfs/format.rs b/crates/core/src/vfs/format.rs index b3f6dee1..91f26eb6 100644 --- a/crates/core/src/vfs/format.rs +++ b/crates/core/src/vfs/format.rs @@ -9,15 +9,15 @@ use runtime_format::{FormatKey, FormatKeyError}; /// To be formatted with [`runtime_format`]. /// /// The following keys are available: -/// - `id`: the snapshot id -/// - `long_id`: the snapshot id as a string -/// - `time`: the snapshot time -/// - `username`: the snapshot username -/// - `hostname`: the snapshot hostname -/// - `label`: the snapshot label -/// - `tags`: the snapshot tags -/// - `backup_start`: the snapshot backup start time -/// - `backup_end`: the snapshot backup end time +/// * `id`: the snapshot id +/// * `long_id`: the snapshot id as a string +/// * `time`: the snapshot time +/// * `username`: the snapshot username +/// * `hostname`: the snapshot hostname +/// * `label`: the snapshot label +/// * `tags`: the snapshot tags +/// * `backup_start`: the snapshot backup start time +/// * `backup_end`: the snapshot backup end time #[derive(Debug)] pub(crate) struct FormattedSnapshot<'a> { /// The snapshot file.