Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(errors)!: improve RusticError display and usage #321

Merged
merged 136 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
101f898
Removing anyhow
simonsan Oct 23, 2024
7cdd50e
move error enums to their local files
simonsan Oct 23, 2024
ac5a261
Error handling
simonsan Oct 23, 2024
d8421db
fix typo
simonsan Oct 23, 2024
b690a80
style: format changelog
simonsan Oct 23, 2024
b5a365e
RusticErrors for Choose, Local and Utils
simonsan Oct 23, 2024
36c0ca1
RusticErrors for Local
simonsan Oct 24, 2024
93f99b2
RusticErrors for Local
simonsan Oct 24, 2024
96b4516
style: cargo fmt
simonsan Oct 24, 2024
d51a6ca
remove leftovers from check command error handling draft
simonsan Oct 24, 2024
8af508d
RusticErrors for Check
simonsan Oct 24, 2024
0ecf288
RusticErrors for Cat
simonsan Oct 24, 2024
17f8a35
add context for cat
simonsan Oct 24, 2024
b507c5b
RusticErrors for Dump incl Display for NodeType
simonsan Oct 24, 2024
612ccd1
RusticErrors for forget
simonsan Oct 24, 2024
cfaf6de
RusticErrors for repair
simonsan Oct 24, 2024
9d1534b
RusticErrors for crypto, need std feature for impl Error for aead
simonsan Oct 24, 2024
12d540b
give error code to data decryption error for later usage when matchin…
simonsan Oct 24, 2024
5192bdd
RusticErrors for Cryptographic stuff
simonsan Oct 24, 2024
4563edc
revert check to before draft error handling
simonsan Oct 24, 2024
546b383
RusticErrors for repository
simonsan Oct 24, 2024
98a1c4a
optimize error handling in local hackend
simonsan Oct 24, 2024
4527c21
RusticErrors in restore
simonsan Oct 24, 2024
dee0dfa
more RusticErrors
simonsan Oct 24, 2024
b2c6914
RusticError for polynomial
simonsan Oct 24, 2024
aa5cfc3
use smolstr and box more
simonsan Oct 24, 2024
246a1c7
more RusticErrors
simonsan Oct 24, 2024
3187db8
Merge branch 'main' into refactor/check-error-handling
simonsan Oct 24, 2024
da0032a
Merge branch 'main' into refactor/check-error-handling
simonsan Oct 24, 2024
ed19682
style: fmt
simonsan Oct 24, 2024
f86f4b5
RusticErrors for opendal backend
simonsan Oct 24, 2024
8ff3003
RusticErrors for rclone backend
simonsan Oct 24, 2024
1ab5d8c
Merge branch 'main' into refactor/check-error-handling
simonsan Oct 25, 2024
1856987
RusticErrors for Rclone backend
simonsan Oct 25, 2024
3a045ef
use derive_more display instead of strum for BlobType
simonsan Oct 25, 2024
8ffaa70
RusticErrors for Rest backend
simonsan Oct 25, 2024
27784b2
impl Display for FileType
simonsan Oct 25, 2024
ae1c33d
fix tests for error display and dbg
simonsan Oct 25, 2024
a28089d
test error display and debug impl
simonsan Oct 25, 2024
03c5815
Merge branch 'main' into refactor/check-error-handling
simonsan Oct 25, 2024
9b7c347
Migrate to `with_source` constructor
simonsan Oct 26, 2024
6a540f0
remove wrongly commited macro expanded file
simonsan Oct 26, 2024
7ecc6ca
More RusticErrors
simonsan Oct 26, 2024
942df62
More RusticErrors for Archiver
simonsan Oct 26, 2024
01f9863
RusticErrors for DryRun backend
simonsan Oct 26, 2024
32b63f4
RusticErrors for LocalDestination
simonsan Oct 26, 2024
4e9c408
RusticErrors for Packer and Tree
simonsan Oct 26, 2024
db82ed2
RusticErrors for Cache backend
simonsan Oct 26, 2024
6461492
More RusticErrors
simonsan Oct 26, 2024
9ec6208
More RusticErrors
simonsan Oct 26, 2024
1c672c2
fix error related clippy lints
simonsan Oct 26, 2024
db6ddef
update error
simonsan Oct 26, 2024
85c3c9b
More RusticErrors
simonsan Oct 26, 2024
c45ede8
More RusticErrors from tests
simonsan Oct 26, 2024
f34fb99
more error methods
simonsan Oct 26, 2024
686257f
rename test cases for keys to make more clear their intent
simonsan Oct 26, 2024
cda7b71
Add error code and overwrite guidance to password incorrect error
simonsan Oct 26, 2024
6c3ec5b
Fix tests for incorrect passwort and key files
simonsan Oct 26, 2024
5038925
fix imports
simonsan Oct 26, 2024
e5c9aa1
tests: update snapshots
simonsan Oct 26, 2024
4603d44
make unix build
simonsan Oct 27, 2024
36e9908
fix clippy
simonsan Oct 27, 2024
234cea6
function doc
simonsan Oct 27, 2024
cd0989c
remove unused errors from ignore
simonsan Oct 27, 2024
1d7deaf
fix all `todo!("Error transition")`
simonsan Oct 27, 2024
a480693
Remove compression from error kind and replace with Internal variant
simonsan Oct 27, 2024
56c45af
remove long error types from function docs
simonsan Oct 27, 2024
b31054c
Cleanup errors
simonsan Oct 27, 2024
de1c6e4
fix import
simonsan Oct 27, 2024
2548568
fix reference for fixme
simonsan Oct 27, 2024
10e5886
fix visibility
simonsan Oct 27, 2024
4e19c26
add error handling rules to error module
simonsan Oct 27, 2024
a0ee05d
use `is_code`
simonsan Oct 27, 2024
e7f073d
style: cargo fmt
simonsan Oct 27, 2024
abc5588
imports in backend
simonsan Oct 27, 2024
80bbcec
cleanup backend crate
simonsan Oct 27, 2024
18f2319
re-export for error handling
simonsan Oct 27, 2024
6ed4adf
add back description of errors in fn docs
simonsan Oct 27, 2024
51f6db5
fix path
simonsan Oct 27, 2024
ce4aca7
warn about errors in listing size before throwing out the errors
simonsan Oct 27, 2024
5abc923
format closure
simonsan Oct 27, 2024
1a5a536
Attach error code to verification error
simonsan Oct 27, 2024
3563664
Merge branch 'main' into refactor/check-error-handling
simonsan Oct 28, 2024
6745db4
Use Cow
simonsan Oct 28, 2024
9d694b2
Use SmolStr for `RusticError::new()`
simonsan Oct 28, 2024
5d90807
Add context
simonsan Oct 28, 2024
6453049
remove check issues
simonsan Oct 28, 2024
ff50753
change to unsupported error kind in dump
simonsan Oct 28, 2024
73baca4
change to invalid input error kind in forget
simonsan Oct 28, 2024
dd2c079
specify context better
simonsan Oct 28, 2024
e34d827
attach context for pack_read_header
simonsan Oct 28, 2024
58720c8
attach context for pack_read_header
simonsan Oct 28, 2024
897a339
remove error variants for snapshot file
simonsan Oct 28, 2024
dcfa5ee
AppendOnly errors
simonsan Oct 28, 2024
21528b8
cleanup error in configfile
simonsan Oct 28, 2024
fbf4c4f
order imports
simonsan Oct 28, 2024
2b8caa4
cleanup variants in KeyFileErrorKind
simonsan Oct 28, 2024
80c1ade
cleanup variants in PackerErrorKind
simonsan Oct 28, 2024
858eb2e
cleanup variants in LocalDestinationErrorKind
simonsan Oct 28, 2024
2bfa13c
cleanup variants in TreeErrorKind
simonsan Oct 28, 2024
d0acebf
cleanup variants in PackFileErrorKind
simonsan Oct 28, 2024
8d99678
AppendOnly errors
simonsan Oct 28, 2024
9eaa796
cleanup ErrorKind
simonsan Oct 28, 2024
edb0a97
cleanup ErrorKind
simonsan Oct 28, 2024
caae6bb
cleanup ErrorKind, remove parsing, and spread errors into InvalidInpu…
simonsan Oct 28, 2024
354f7b2
move error kind up in module
simonsan Oct 28, 2024
389b15e
add back error
simonsan Oct 28, 2024
23db926
more InvalidInput errors
simonsan Oct 28, 2024
4f44079
update snapshot file for error display test
simonsan Oct 28, 2024
b484c37
log errors before throwing them away
simonsan Oct 29, 2024
f4babc3
adapt visibility to make `rustic-rs` build
simonsan Oct 29, 2024
a7c8360
update dep
simonsan Oct 29, 2024
b6a8386
fix local after review
simonsan Oct 30, 2024
c8ed8df
.ask_report()
simonsan Oct 30, 2024
d6d42f3
don't unwrap in error description
simonsan Oct 30, 2024
be71df2
reorder error to be aligned with display impl
simonsan Oct 30, 2024
b8bd50d
DRY constructors for RusticError
simonsan Oct 30, 2024
e508412
update error snapshots
simonsan Oct 30, 2024
63e496b
allow clippy lint for too many lines (103/100)
simonsan Oct 30, 2024
5d41598
Make it possible to use multiple different issue urls for an error
simonsan Oct 30, 2024
8e8abe1
update error kind and error display impl
simonsan Oct 30, 2024
8dab388
replace placeholders based on context keys in guidance
simonsan Oct 30, 2024
72f1782
Use the context placeholders in the guidance messages
simonsan Oct 30, 2024
b98e35b
attach more context to errors that are already RusticErrors
simonsan Oct 30, 2024
17180a6
add instructions about forwarding RusticError in a `map_err`
simonsan Oct 30, 2024
125e7e2
update error display
simonsan Nov 1, 2024
8baaf40
refactor: use `ecow` instead of `smol_str` due to recommendation
simonsan Nov 5, 2024
04feb7a
Remove `Command` variant from ErrorKind.
simonsan Nov 5, 2024
ed4c005
fix(clippy): lints
simonsan Nov 5, 2024
7a910ab
upgrade thiserror to 2.0.0
simonsan Nov 7, 2024
37dd5cb
Merge branch 'main' into refactor/check-error-handling
simonsan Nov 9, 2024
abb5973
Merge branch 'main' into refactor/check-error-handling
simonsan Nov 16, 2024
c330148
cache: use warning and ignore non-existing cache dirs
aawsome Nov 16, 2024
2aa5b50
shorten error message
aawsome Nov 16, 2024
388c9ca
fix some issues after review
simonsan Nov 16, 2024
74a0bd3
clippy: allow many lines for impl Display
simonsan Nov 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 87 additions & 48 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ resolver = "2"
rust-version = "1.76.0"

[workspace.dependencies]
# Internal Dependencies
rustic_backend = { path = "crates/backend", version = "0" }
rustic_core = { path = "crates/core", version = "0" }
rustic_testing = { path = "crates/testing", version = "0" }

aho-corasick = "1.1.3"
anyhow = "1.0.89"
bytes = "1.7.2"
displaydoc = "0.2.5"
enum-map = "2.7.3"
rustic_backend = { path = "crates/backend" }
rustic_core = { path = "crates/core", version = "0" }
rustic_testing = { path = "crates/testing", version = "0" }
log = "0.4.22"
simplelog = "0.12.2"
thiserror = "2.0.0"

# dev-dependencies
rstest = "0.23.0"
Expand Down
10 changes: 5 additions & 5 deletions crates/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ rclone = ["rest", "dep:rand", "dep:semver"]
rustic_core = { workspace = true }

# errors
anyhow = "1.0.89"
displaydoc = "0.2.5"
thiserror = "1.0.64"
displaydoc = { workspace = true }
thiserror = { workspace = true }

# logging
log = "0.4.22"
log = { workspace = true }

# other dependencies
bytes = "1.7.2"
bytes = { workspace = true }
derive_setters = "0.1.6"
humantime = "2.1.0"
itertools = "0.13.0"
Expand Down Expand Up @@ -101,6 +100,7 @@ opendal = { version = "0.50.0", features = ["services-b2", "services-sftp", "ser
opendal = { version = "0.50.0", features = ["services-b2", "services-swift", "services-azblob", "services-azdls", "services-cos", "services-fs", "services-ftp", "services-dropbox", "services-gdrive", "services-gcs", "services-ghac", "services-http", "services-ipmfs", "services-memory", "services-obs", "services-onedrive", "services-oss", "services-s3", "services-webdav", "services-webhdfs", "services-azfile", "layers-blocking", "layers-throttle"], optional = true }

[dev-dependencies]
anyhow = { workspace = true }
rstest = { workspace = true }
toml = "0.8.19"

Expand Down
37 changes: 21 additions & 16 deletions crates/backend/src/choose.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
//! This module contains [`BackendOptions`] and helpers to choose a backend from a given url.
use anyhow::{anyhow, Result};
use derive_setters::Setters;
use std::{collections::HashMap, sync::Arc};
use strum_macros::{Display, EnumString};

#[allow(unused_imports)]
use rustic_core::{RepositoryBackends, WriteBackend};
use rustic_core::{ErrorKind, RepositoryBackends, RusticError, RusticResult, WriteBackend};

use crate::{
error::BackendAccessErrorKind,
local::LocalBackend,
util::{location_to_type_and_path, BackendLocation},
};
Expand Down Expand Up @@ -75,12 +72,17 @@ impl BackendOptions {
/// # Returns
///
/// The backends for the repository.
pub fn to_backends(&self) -> Result<RepositoryBackends> {
pub fn to_backends(&self) -> RusticResult<RepositoryBackends> {
let mut options = self.options.clone();
options.extend(self.options_cold.clone());
let be = self
.get_backend(self.repository.as_ref(), options)?
.ok_or_else(|| anyhow!("No repository given."))?;
.ok_or_else(|| {
RusticError::new(
ErrorKind::Backend,
"No repository given. Please make sure, that you have set the repository.",
)
})?;
let mut options = self.options.clone();
options.extend(self.options_hot.clone());
let be_hot = self.get_backend(self.repo_hot.as_ref(), options)?;
Expand All @@ -97,7 +99,7 @@ impl BackendOptions {
///
/// # Errors
///
/// If the backend cannot be loaded, an error is returned.
/// * If the backend cannot be loaded, an error is returned.
///
/// # Returns
///
Expand All @@ -108,13 +110,18 @@ impl BackendOptions {
&self,
repo_string: Option<&String>,
options: HashMap<String, String>,
) -> Result<Option<Arc<dyn WriteBackend>>> {
) -> RusticResult<Option<Arc<dyn WriteBackend>>> {
repo_string
.map(|string| {
let (be_type, location) = location_to_type_and_path(string)?;
be_type.to_backend(location, options.into()).map_err(|err| {
BackendAccessErrorKind::BackendLoadError(be_type.to_string(), err).into()
})
be_type
.to_backend(location.clone(), options.into())
.map_err(|err| {
err
.prepend_guidance_line("Could not load the backend `{name}` at `{location}`. Please check the given backend and try again.")
.attach_context("name", be_type.to_string())
.attach_context("location", location.to_string())
})
})
.transpose()
}
Expand All @@ -131,14 +138,12 @@ pub trait BackendChoice {
///
/// # Errors
///
/// * [`BackendAccessErrorKind::BackendNotSupported`] - If the backend is not supported.
///
/// [`BackendAccessErrorKind::BackendNotSupported`]: crate::error::BackendAccessErrorKind::BackendNotSupported
/// * If the backend is not supported.
fn to_backend(
&self,
location: BackendLocation,
options: Option<HashMap<String, String>>,
) -> Result<Arc<dyn WriteBackend>>;
) -> RusticResult<Arc<dyn WriteBackend>>;
}

/// The supported backend types.
Expand Down Expand Up @@ -176,7 +181,7 @@ impl BackendChoice for SupportedBackend {
&self,
location: BackendLocation,
options: Option<HashMap<String, String>>,
) -> Result<Arc<dyn WriteBackend>> {
) -> RusticResult<Arc<dyn WriteBackend>> {
let options = options.unwrap_or_default();

Ok(match self {
Expand Down
134 changes: 0 additions & 134 deletions crates/backend/src/error.rs

This file was deleted.

24 changes: 14 additions & 10 deletions crates/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,22 @@ This crate exposes a few features for controlling dependency usage:
*/

pub mod choose;
/// Error types for the backend.
pub mod error;
/// Local backend for Rustic.
pub mod local;
/// Utility functions for the backend.
pub mod util;

/// `OpenDAL` backend for Rustic.
#[cfg(feature = "opendal")]
pub mod opendal;

/// `Rclone` backend for Rustic.
#[cfg(feature = "rclone")]
pub mod rclone;

/// REST backend for Rustic.
#[cfg(feature = "rest")]
pub mod rest;
/// Utility functions for the backend.
pub mod util;

// rustic_backend Public API
pub use crate::{
choose::{BackendOptions, SupportedBackend},
local::LocalBackend,
};

#[cfg(feature = "opendal")]
pub use crate::opendal::OpenDALBackend;
Expand All @@ -83,3 +78,12 @@ pub use crate::rclone::RcloneBackend;

#[cfg(feature = "rest")]
pub use crate::rest::RestBackend;

// rustic_backend Public API
pub use crate::{
choose::{BackendOptions, SupportedBackend},
local::LocalBackend,
};

// re-export for error handling
pub use rustic_core::{ErrorKind, RusticError, RusticResult, Severity, Status};
Loading
Loading