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

fix(commands): return error if check fails #224

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

aawsome
Copy link
Member

@aawsome aawsome commented May 6, 2024

closes #222

@aawsome aawsome changed the title check: return error if check fails fix(commands): return error if check fails May 6, 2024
Copy link

codecov bot commented May 6, 2024

Codecov Report

Attention: Patch coverage is 54.49735% with 86 lines in your changes missing coverage. Please review.

Project coverage is 43.4%. Comparing base (1e7b4a8) to head (5b98b3b).

Additional details and impacted files
Files Coverage Δ
crates/core/src/error.rs 14.2% <ø> (ø)
crates/core/src/repository.rs 34.7% <42.8%> (+0.2%) ⬆️
crates/core/src/commands/check.rs 55.8% <54.9%> (-7.8%) ⬇️

... and 21 files with indirect coverage changes

crates/core/src/commands/check.rs Outdated Show resolved Hide resolved
crates/core/src/error.rs Outdated Show resolved Hide resolved
crates/core/src/lib.rs Outdated Show resolved Hide resolved
@aawsome aawsome requested a review from simonsan May 28, 2024 15:26
@simonsan
Copy link
Contributor

I'll look through it tomorrow. 👍🏽

pub enum CheckErrorLevel {
/// A warning: Something is strange and should be corrected, but repository integrity is not affected.
Warn,
/// An erro: Something in the repository is not as it should be.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An erro: Something in the repository is not as it should be.
/// An error: Something in the repository is not as it should be.

Comment on lines +50 to +55
#[derive(Debug)]
/// `CheckResults` is a list of errors encountered during the check.
pub struct CheckResults {
/// The list of errors with severity level.
pub errors: Vec<(CheckErrorLevel, CheckError)>,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we could replace these with: https://crates.io/crates/lazy_errors

Didn't use it, but it sounded interesting on Reddit last week: https://www.reddit.com/r/rust/comments/1ddi1nb/i_published_my_first_crate_lazy_errors/

#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
/// `CheckErrorLevel` describes severity levels of problems identified by check.
pub enum CheckErrorLevel {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably stick to the kind naming scheme we have in rustic_core, so something like CheckErrorKind.

pub(crate) fn run<P: ProgressBars, S: Open>(self, repo: &Repository<P, S>) -> RusticResult<()> {
pub(crate) fn check<P: ProgressBars, S: Open>(
&self,
opts: CheckOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that much better, it's a good usage of structs, to pass these inside like this, so it's also easy to impl Default on CheckOptions 👍🏽

Comment on lines 124 to +125
// TODO: Make concurrency (20) customizable
check_cache_files(20, cache, raw_be, file_type, &p)?;
self.check_cache_files(20, cache, raw_be, file_type, &p)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, if that could be just a field in CheckOptions? or maybe another struct ParallelismOptions composed into CheckOptions that we can use in rustic_core.

Comment on lines 148 to +149
// TODO: Make concurrency (5) customizable
check_cache_files(5, cache, raw_be, FileType::Pack, &p)?;
self.check_cache_files(5, cache, raw_be, FileType::Pack, &p)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, maybe ParallelismOptions could be useful here as well?

Err(err) => error!("Error reading pack {id} : {err}",),
Err(err) => self.add_error(CheckError::ErrorReadingPack {
id,
err: Box::new(err),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would call it source so it's more clear

}
self.errors
.lock()
.unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would at least prefer an expect here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error handling in check
2 participants