Skip to content

Commit

Permalink
attach more context to errors that are already RusticErrors
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Oct 30, 2024
1 parent 72f1782 commit b98e35b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
11 changes: 4 additions & 7 deletions crates/backend/src/choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ impl BackendOptions {
be_type
.to_backend(location.clone(), options.into())
.map_err(|err| {
RusticError::with_source(
ErrorKind::Backend,
"Could not load the backend `{name}` at `{location}`. Please check the given backend and try again.",
err,
)
.attach_context("name", be_type.to_string())
.attach_context("location", location.to_string())
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 Down
8 changes: 3 additions & 5 deletions crates/core/src/archiver/file_archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ impl<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> FileArchiver<'a, BE, I> {
)?
.open()
.map_err(|err| {
RusticError::with_source(
ErrorKind::InputOutput,
"Failed to open ReadSourceOpen at `{path}`",
err,
)
err
.overwrite_kind(ErrorKind::InputOutput)
.prepend_guidance_line("Failed to open ReadSourceOpen at `{path}`")
.attach_context("path", path.display().to_string())
})?;

Expand Down
21 changes: 10 additions & 11 deletions crates/core/src/blob/packer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,9 @@ impl<BE: DecryptWriteBackend> RawPacker<BE> {
/// * If the packfile could not be saved
fn finalize(&mut self) -> RusticResult<PackerStats> {
self.save().map_err(|err| {
RusticError::with_source(
ErrorKind::Internal,
"Failed to save packfile. Data may be lost.",
err,
)
.ask_report()
err.overwrite_kind(ErrorKind::Internal)
.prepend_guidance_line("Failed to save packfile. Data may be lost.")
.ask_report()
})?;

self.file_writer.take().unwrap().finalize()?;
Expand Down Expand Up @@ -920,6 +917,7 @@ impl<BE: DecryptFullBackend> Repacker<BE> {
blob.offset,
blob.length,
)?;

self.packer
.add_raw(
&data,
Expand All @@ -929,12 +927,13 @@ impl<BE: DecryptFullBackend> Repacker<BE> {
Some(self.size_limit),
)
.map_err(|err| {
RusticError::with_source(
ErrorKind::Internal,
"Failed to fast-add (unchecked) blob to packfile.",
err,
)
err.overwrite_kind(ErrorKind::Internal)
.prepend_guidance_line(
"Failed to fast-add (unchecked) blob `{blob_id}` to packfile.",
)
.attach_context("blob_id", blob.id.to_string())
})?;

Ok(())
}

Expand Down
5 changes: 1 addition & 4 deletions crates/core/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ impl<P: ProgressBars, S> Repository<P, S> {
/// The result of the warm up
pub fn warm_up(&self, packs: impl ExactSizeIterator<Item = PackId>) -> RusticResult<()> {
warm_up(self, packs)
.map_err(|err| RusticError::with_source(ErrorKind::Command, "Warm-up failed.", err))
}

/// Warm up the given pack files and wait the configured waiting time.
Expand All @@ -728,9 +727,7 @@ impl<P: ProgressBars, S> Repository<P, S> {
/// * If the command could not be parsed.
/// * If the thread pool could not be created.
pub fn warm_up_wait(&self, packs: impl ExactSizeIterator<Item = PackId>) -> RusticResult<()> {
warm_up_wait(self, packs).map_err(|err| {
RusticError::with_source(ErrorKind::Command, "Warm-up with waiting time failed.", err)
})
warm_up_wait(self, packs)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/vfs/webdavfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<P: Debug + Send + Sync + 'static, S: IndexedFull + Debug + Send + Sync + 's
.inner
.repo
.open_file(&node)
.map_err(|_| FsError::GeneralFailure)?;
.map_err(|_err| FsError::GeneralFailure)?;
let file: Box<dyn DavFile> = Box::new(DavFsFile {
node,
open,
Expand Down Expand Up @@ -274,7 +274,7 @@ impl<P: Debug + Send + Sync, S: IndexedFull + Debug + Send + Sync> DavFile for D
.fs
.repo
.read_file_at(&self.open, self.seek, count)
.map_err(|_| FsError::GeneralFailure)?;
.map_err(|_err| FsError::GeneralFailure)?;
self.seek += data.len();
Ok(data)
}
Expand Down

0 comments on commit b98e35b

Please sign in to comment.