From 72f17827cc7c10bfe05bee5d57c99567659f531e Mon Sep 17 00:00:00 2001 From: simonsan <14062932+simonsan@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:34:30 +0100 Subject: [PATCH] Use the context placeholders in the guidance messages Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com> --- crates/backend/src/choose.rs | 2 +- crates/backend/src/local.rs | 73 +++++++++-------- crates/backend/src/opendal.rs | 47 ++++++----- crates/backend/src/rclone.rs | 16 ++-- crates/backend/src/rest.rs | 28 ++++--- crates/backend/src/util.rs | 2 +- crates/core/src/archiver/file_archiver.rs | 6 +- crates/core/src/archiver/tree_archiver.rs | 10 ++- crates/core/src/backend.rs | 11 ++- crates/core/src/backend/cache.rs | 86 +++++++++++++------- crates/core/src/backend/decrypt.rs | 9 +- crates/core/src/backend/ignore.rs | 24 +++--- crates/core/src/backend/local_destination.rs | 4 +- crates/core/src/blob/packer.rs | 42 +++++----- crates/core/src/blob/tree.rs | 63 ++++++++------ crates/core/src/commands/backup.rs | 33 +++++--- crates/core/src/commands/cat.rs | 2 +- crates/core/src/commands/check.rs | 28 ++++--- crates/core/src/commands/config.rs | 24 +++--- crates/core/src/commands/dump.rs | 4 +- crates/core/src/commands/merge.rs | 12 ++- crates/core/src/commands/prune.rs | 36 ++++---- crates/core/src/commands/repair/index.rs | 14 +--- crates/core/src/commands/restore.rs | 14 ++-- crates/core/src/id.rs | 2 +- crates/core/src/index.rs | 9 +- crates/core/src/repofile/configfile.rs | 4 +- crates/core/src/repofile/keyfile.rs | 4 +- crates/core/src/repofile/packfile.rs | 23 +++--- crates/core/src/repofile/snapshotfile.rs | 8 +- crates/core/src/repository.rs | 26 +++--- crates/core/src/repository/warm_up.rs | 2 +- crates/core/src/vfs.rs | 38 +++++---- crates/testing/src/backend.rs | 12 ++- 34 files changed, 406 insertions(+), 312 deletions(-) diff --git a/crates/backend/src/choose.rs b/crates/backend/src/choose.rs index ad8d1009..1eee995f 100644 --- a/crates/backend/src/choose.rs +++ b/crates/backend/src/choose.rs @@ -119,7 +119,7 @@ impl BackendOptions { .map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Could not load the backend. Please check the given backend and try again.", + "Could not load the backend `{name}` at `{location}`. Please check the given backend and try again.", err, ) .attach_context("name", be_type.to_string()) diff --git a/crates/backend/src/local.rs b/crates/backend/src/local.rs index f17e9dfc..82685915 100644 --- a/crates/backend/src/local.rs +++ b/crates/backend/src/local.rs @@ -134,10 +134,14 @@ impl LocalBackend { debug!("calling {actual_command}..."); let command: CommandInput = actual_command.parse().map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Failed to parse command input.", err) - .attach_context("command", actual_command) - .attach_context("replacement", replace_with.join(", ")) - .ask_report() + RusticError::with_source( + ErrorKind::Internal, + "Failed to parse command input: `{command}` is not a valid command.", + err, + ) + .attach_context("command", actual_command) + .attach_context("replacement", replace_with.join(", ")) + .ask_report() })?; let status = Command::new(command.command()) @@ -146,21 +150,22 @@ impl LocalBackend { .map_err(|err| { RusticError::with_source( ErrorKind::Command, - "Failed to execute command. Please check the command and try again.", + "Failed to execute `{command}`. Please check the command and try again.", err, ) .attach_context("command", command.to_string()) })?; if !status.success() { - return Err( - RusticError::new(ErrorKind::Command, "Command was not successful.") - .attach_context("command", command.to_string()) - .attach_context("file_name", replace_with[0]) - .attach_context("file_type", replace_with[1]) - .attach_context("id", replace_with[2]) - .attach_context("status", status.to_string()), - ); + return Err(RusticError::new( + ErrorKind::Command, + "Command was not successful: `{command}` failed with status `{status}`.", + ) + .attach_context("command", command.to_string()) + .attach_context("file_name", replace_with[0]) + .attach_context("file_type", replace_with[1]) + .attach_context("id", replace_with[2]) + .attach_context("status", status.to_string())); } Ok(()) } @@ -230,7 +235,7 @@ impl ReadBackend for LocalBackend { let metadata = path.metadata().map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Failed to query metadata of the file. Please check the file and try again.", + "Failed to query metadata of the file `{path}`. Please check the file and try again.", err ) .attach_context("path", path.to_string_lossy()) @@ -239,7 +244,7 @@ impl ReadBackend for LocalBackend { metadata.len().try_into().map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Failed to convert file length to u32.", + "Failed to convert file length `{length}` to u32.", err, ) .attach_context("length", metadata.len().to_string()) @@ -268,7 +273,7 @@ impl ReadBackend for LocalBackend { .map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Failed to query metadata of the file. Please check the file and try again.", + "Failed to query metadata of the file `{path}`. Please check the file and try again.", err ) .attach_context("path", e.path().to_string_lossy()) @@ -281,7 +286,7 @@ impl ReadBackend for LocalBackend { .map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Failed to convert file length to u32.", + "Failed to convert file length `{length}` to u32.", err ) .attach_context("length", metadata.len().to_string()) @@ -353,7 +358,7 @@ impl ReadBackend for LocalBackend { let mut file = File::open(self.path(tpe, id)).map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Failed to open the file. Please check the file and try again.", + "Failed to open the file `{path}`. Please check the file and try again.", err, ) .attach_context("path", self.path(tpe, id).to_string_lossy()) @@ -361,7 +366,7 @@ impl ReadBackend for LocalBackend { _ = file.seek(SeekFrom::Start(offset.into())).map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Failed to seek to the position in the file. Please check the file and try again.", + "Failed to seek to the position `{offset}` in the file `{path}`. Please check the file and try again.", err, ) .attach_context("path", self.path(tpe, id).to_string_lossy()) @@ -373,7 +378,7 @@ impl ReadBackend for LocalBackend { length.try_into().map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Failed to convert length to u64.", + "Failed to convert length `{length}` to u64.", err, ) .attach_context("length", length.to_string()) @@ -384,7 +389,7 @@ impl ReadBackend for LocalBackend { file.read_exact(&mut vec).map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Failed to read the exact length of the file. Please check the file and try again.", + "Failed to read the exact length `{length}` of the file `{path}`. Please check the file and try again.", err, ) .attach_context("path", self.path(tpe, id).to_string_lossy()) @@ -406,7 +411,7 @@ impl WriteBackend for LocalBackend { fs::create_dir_all(&self.path).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to create the directory. Please check the path and try again.", + "Failed to create the directory `{path}`. Please check the path and try again.", err, ) .attach_context("path", self.path.display().to_string()) @@ -417,7 +422,7 @@ impl WriteBackend for LocalBackend { fs::create_dir_all(path.clone()).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to create the directory. Please check the path and try again.", + "Failed to create the directory `{path}`. Please check the path and try again.", err, ) .attach_context("path", path.display().to_string()) @@ -429,7 +434,7 @@ impl WriteBackend for LocalBackend { fs::create_dir_all(path.clone()).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to create the directory. Please check the path and try again.", + "Failed to create the directory `{path}`. Please check the path and try again.", err, ) .attach_context("path", path.display().to_string()) @@ -472,21 +477,25 @@ impl WriteBackend for LocalBackend { .map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to open the file. Please check the file and try again.", + "Failed to open the file `{path}`. Please check the file and try again.", err, ) .attach_context("path", filename.to_string_lossy()) })?; file.set_len(buf.len().try_into().map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Failed to convert length to u64.", err) - .attach_context("length", buf.len().to_string()) - .ask_report() + RusticError::with_source( + ErrorKind::Internal, + "Failed to convert length `{length}` to u64.", + err, + ) + .attach_context("length", buf.len().to_string()) + .ask_report() })?) .map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to set the length of the file. Please check the file and try again.", + "Failed to set the length of the file `{path}`. Please check the file and try again.", err, ) .attach_context("path", filename.to_string_lossy()) @@ -495,7 +504,7 @@ impl WriteBackend for LocalBackend { file.write_all(&buf).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to write to the buffer. Please check the file and try again.", + "Failed to write to the buffer: `{path}`. Please check the file and try again.", err, ) .attach_context("path", filename.to_string_lossy()) @@ -504,7 +513,7 @@ impl WriteBackend for LocalBackend { file.sync_all().map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to sync OS Metadata to disk. Please check the file and try again.", + "Failed to sync OS Metadata to disk: `{path}`. Please check the file and try again.", err, ) .attach_context("path", filename.to_string_lossy()) @@ -535,7 +544,7 @@ impl WriteBackend for LocalBackend { fs::remove_file(&filename).map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Failed to remove the file. Was the file already removed or is it in use? Please check the file and remove it manually.", + "Failed to remove the file `{path}`. Was the file already removed or is it in use? Please check the file and remove it manually.", err ) .attach_context("path", filename.to_string_lossy()) diff --git a/crates/backend/src/opendal.rs b/crates/backend/src/opendal.rs index a0b8a333..e1fb71fa 100644 --- a/crates/backend/src/opendal.rs +++ b/crates/backend/src/opendal.rs @@ -55,21 +55,24 @@ impl FromStr for Throttle { ByteSize::from_str(s.trim()).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Parsing ByteSize from throttle string failed", + "Parsing ByteSize from throttle string `{string}` failed", err, ) .attach_context("string", s) }) }) .map(|b| -> RusticResult { - b?.as_u64().try_into().map_err(|err| { + let bytesize = b?.as_u64(); + bytesize.try_into().map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Converting ByteSize to u32 failed", + "Converting ByteSize `{bytesize}` to u32 failed", err, ) + .attach_context("bytesize", bytesize.to_string()) }) }); + let bandwidth = values .next() .transpose()? @@ -106,7 +109,7 @@ impl OpenDALBackend { Some(value) => usize::from_str(value).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Parsing retry value failed, the value must be a valid integer.", + "Parsing retry value `{value}` failed, the value must be a valid integer.", err, ) .attach_context("value", value.to_string()) @@ -118,7 +121,7 @@ impl OpenDALBackend { usize::from_str(c).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Parsing connections value failed, the value must be a valid integer.", + "Parsing connections value `{value}` failed, the value must be a valid integer.", err, ) .attach_context("value", c.to_string()) @@ -134,7 +137,7 @@ impl OpenDALBackend { let schema = Scheme::from_str(path.as_ref()).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Parsing scheme from path failed, the path must contain a valid scheme.", + "Parsing scheme from path `{path}` failed, the path must contain a valid scheme.", err, ) .attach_context("path", path.as_ref().to_string()) @@ -143,7 +146,7 @@ impl OpenDALBackend { .map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Creating Operator failed. Please check the given schema and options.", + "Creating Operator from path `{path}` failed. Please check the given schema and options.", err, ) .attach_context("path", path.as_ref().to_string()) @@ -244,7 +247,7 @@ impl ReadBackend for OpenDALBackend { .map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Listing all files failed in the backend. Please check if the given path is correct.", + "Listing all files of `{path}` failed in the backend. Please check if the given path is correct.", err, ) .attach_context("path", path) @@ -271,17 +274,17 @@ impl ReadBackend for OpenDALBackend { entry.content_length().try_into().map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Parsing content length failed", + "Parsing content length `{length}` failed", err, ) - .attach_context("content length", entry.content_length().to_string()) + .attach_context("length", entry.content_length().to_string()) })?, )]), Err(err) if err.kind() == opendal::ErrorKind::NotFound => Ok(Vec::new()), Err(err) => Err(err).map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Getting Metadata of `config` failed in the backend. Please check if the `config` exists.", + "Getting Metadata of type `{type}` failed in the backend. Please check if `{type}` exists.", err, ) .attach_context("type", tpe.to_string()) @@ -299,7 +302,7 @@ impl ReadBackend for OpenDALBackend { .map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Listing all files in directory and their sizes failed in the backend. Please check if the given path is correct.", + "Listing all files of `{type}` in directory `{path}` and their sizes failed in the backend. Please check if the given path is correct.", err, ) .attach_context("path", path) @@ -316,10 +319,10 @@ impl ReadBackend for OpenDALBackend { .map_err(|err| RusticError::with_source( ErrorKind::Internal, - "Parsing content length failed", + "Parsing content length `{length}` failed", err, ) - .attach_context("content length", e.metadata().content_length().to_string()) + .attach_context("length", e.metadata().content_length().to_string()) )?, )) }) @@ -342,7 +345,7 @@ impl ReadBackend for OpenDALBackend { .map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Reading file failed in the backend. Please check if the given path is correct.", + "Reading file `{path}` failed in the backend. Please check if the given path is correct.", err, ) .attach_context("path", path) @@ -372,7 +375,7 @@ impl ReadBackend for OpenDALBackend { .map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Partially reading file failed in the backend. Please check if the given path is correct.", + "Partially reading file `{path}` failed in the backend. Please check if the given path is correct.", err, ) .attach_context("path", path) @@ -397,11 +400,11 @@ impl WriteBackend for OpenDALBackend { .map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Creating directory failed in the backend. Please check if the given path is correct.", + "Creating directory `{path}` failed in the backend `{location}`. Please check if the given path is correct.", err, ) - .attach_context("location", self.location()) .attach_context("path", path) + .attach_context("location", self.location()) .attach_context("type", tpe.to_string()) )?; } @@ -418,11 +421,11 @@ impl WriteBackend for OpenDALBackend { self.operator.create_dir(&path).map_err(|err| RusticError::with_source( ErrorKind::Backend, - "Creating directory failed in the backend. Please check if the given path is correct.", + "Creating directory `{path}` failed in the backend `{location}`. Please check if the given path is correct.", err, ) - .attach_context("location", self.location()) .attach_context("path", path) + .attach_context("location", self.location()) ) })?; @@ -449,7 +452,7 @@ impl WriteBackend for OpenDALBackend { self.operator.write(&filename, buf).map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Writing file failed in the backend. Please check if the given path is correct.", + "Writing file `{path}` failed in the backend. Please check if the given path is correct.", err, ) .attach_context("path", filename) @@ -473,7 +476,7 @@ impl WriteBackend for OpenDALBackend { self.operator.delete(&filename).map_err(|err| { RusticError::with_source( ErrorKind::Backend, - "Deleting file failed in the backend. Please check if the given path is correct.", + "Deleting file `{path}` failed in the backend. Please check if the given path is correct.", err, ) .attach_context("path", filename) diff --git a/crates/backend/src/rclone.rs b/crates/backend/src/rclone.rs index 60b97b7d..24836cf4 100644 --- a/crates/backend/src/rclone.rs +++ b/crates/backend/src/rclone.rs @@ -85,7 +85,7 @@ fn check_clone_version(rclone_version_output: &[u8]) -> RusticResult<()> { let mut parsed_version = Version::parse(rclone_version).map_err(|err| { RusticError::with_source(ErrorKind::Internal, - "Error parsing rclone version. This should not happen. Please check the `rclone version` output manually.", + "Error parsing rclone version `{version}`. This should not happen. Please check the `rclone version` output manually.", err) .attach_context("version", rclone_version) })?; @@ -113,9 +113,9 @@ fn check_clone_version(rclone_version_output: &[u8]) -> RusticResult<()> { { return Err(RusticError::new( ErrorKind::Unsupported, - "Unsupported rclone version. We must not use rclone without authentication! Please upgrade to rclone >= 1.52.2!", + "Unsupported rclone version `{version}`. We must not use rclone without authentication! Please upgrade to rclone >= 1.52.2!", ) - .attach_context("current version", rclone_version.to_string())); + .attach_context("version", rclone_version.to_string())); } Ok(()) @@ -205,10 +205,10 @@ impl RcloneBackend { .map_err(|err| RusticError::with_source( ErrorKind::ExternalCommand, - "Experienced an error while running rclone. Please check if rclone is installed and working correctly.", + "Experienced an error while running rclone: `{rclone_command}`. Please check if rclone is installed and working correctly.", err ) - .attach_context("rclone command", rclone_command.to_string()) + .attach_context("rclone_command", rclone_command.to_string()) )?; let mut stderr = BufReader::new( @@ -234,8 +234,8 @@ impl RcloneBackend { return Err( RusticError::new( ErrorKind::ExternalCommand, - "rclone exited before it could start the REST server. Please check the exit status for more information.", - ).attach_context("exit status", status.to_string()) + "rclone exited before it could start the REST server: `{exit_status}`. Please check the exit status for more information.", + ).attach_context("exit_status", status.to_string()) ); } let mut line = String::new(); @@ -270,7 +270,7 @@ impl RcloneBackend { if !rest_url.starts_with("http://") { return Err(RusticError::new( ErrorKind::InputOutput, - "Please make sure, the URL starts with 'http://'!", + "Please make sure, the URL `{url}` starts with 'http://'!", ) .attach_context("url", rest_url)); } diff --git a/crates/backend/src/rest.rs b/crates/backend/src/rest.rs index b9357ca9..2293afa6 100644 --- a/crates/backend/src/rest.rs +++ b/crates/backend/src/rest.rs @@ -155,7 +155,7 @@ impl RestBackend { }; let url = Url::parse(&url).map_err(|err| { - RusticError::with_source(ErrorKind::InvalidInput, "URL parsing failed", err) + RusticError::with_source(ErrorKind::InvalidInput, "URL `{url}` parsing failed", err) .attach_context("url", url) })?; @@ -180,7 +180,7 @@ impl RestBackend { _ => usize::from_str(&value).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Cannot parse value, invalid value for option retry.", + "Cannot parse value `{value}`, invalid value for option `{option}`.", err, ) .attach_context("value", value) @@ -192,7 +192,7 @@ impl RestBackend { let timeout = humantime::Duration::from_str(&value).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Could not parse value as `humantime` duration.", + "Could not parse value `{value}` as `humantime` duration. Invalid value for option `{option}`.", err, ) .attach_context("value", value) @@ -293,10 +293,10 @@ impl ReadBackend for RestBackend { }; let url = self.url.join(&path).map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Joining URL failed", err) + RusticError::with_source(ErrorKind::Internal, "Joining URL `{url}` failed", err) .attach_context("url", self.url.as_str()) .attach_context("tpe", tpe.to_string()) - .attach_context("tpe dir", tpe.dirname().to_string()) + .attach_context("tpe_dir", tpe.dirname().to_string()) })?; backoff::retry_notify( @@ -391,10 +391,10 @@ impl ReadBackend for RestBackend { let offset2 = offset + length - 1; let header_value = format!("bytes={offset}-{offset2}"); let url = self.url(tpe, id).map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Joining URL failed", err) + RusticError::with_source(ErrorKind::Internal, "Joining URL `{url}` failed", err) .attach_context("url", self.url.as_str()) .attach_context("tpe", tpe.to_string()) - .attach_context("tpe dir", tpe.dirname().to_string()) + .attach_context("tpe_dir", tpe.dirname().to_string()) .attach_context("id", id.to_string()) })?; @@ -429,10 +429,10 @@ fn construct_join_url_error( id: &Id, self_url: &Url, ) -> Box { - RusticError::with_source(ErrorKind::Internal, "Joining URL failed", err) + RusticError::with_source(ErrorKind::Internal, "Joining URL `{url}` failed", err) .attach_context("url", self_url.as_str()) .attach_context("tpe", tpe.to_string()) - .attach_context("tpe dir", tpe.dirname().to_string()) + .attach_context("tpe_dir", tpe.dirname().to_string()) .attach_context("id", id.to_string()) } @@ -444,9 +444,13 @@ impl WriteBackend for RestBackend { /// * If the backoff failed. fn create(&self) -> RusticResult<()> { let url = self.url.join("?create=true").map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Joining URL failed", err) - .attach_context("url", self.url.as_str()) - .attach_context("join input", "?create=true") + RusticError::with_source( + ErrorKind::Internal, + "Joining URL `{url}` with `{join_input}` failed", + err, + ) + .attach_context("url", self.url.as_str()) + .attach_context("join_input", "?create=true") })?; backoff::retry_notify( diff --git a/crates/backend/src/util.rs b/crates/backend/src/util.rs index 4e725a4d..d1ff6928 100644 --- a/crates/backend/src/util.rs +++ b/crates/backend/src/util.rs @@ -61,7 +61,7 @@ pub fn location_to_type_and_path( SupportedBackend::try_from(scheme).map_err(|err| { RusticError::with_source( ErrorKind::Unsupported, - "The backend type is not supported. Please check the given backend and try again.", + "The backend type `{name}` is not supported. Please check the given backend and try again.", err ) .attach_context("name", scheme) diff --git a/crates/core/src/archiver/file_archiver.rs b/crates/core/src/archiver/file_archiver.rs index d0e7ba6b..33a614bb 100644 --- a/crates/core/src/archiver/file_archiver.rs +++ b/crates/core/src/archiver/file_archiver.rs @@ -118,7 +118,7 @@ impl<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> FileArchiver<'a, BE, I> { .ok_or_else( || RusticError::new( ErrorKind::Internal, - "Failed to unpack tree type optional. Option should contain a value, but contained `None`.", + "Failed to unpack tree type optional at `{path}`. Option should contain a value, but contained `None`.", ) .attach_context("path", path.display().to_string()) .ask_report(), @@ -127,7 +127,7 @@ impl<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> FileArchiver<'a, BE, I> { .map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to open ReadSourceOpen", + "Failed to open ReadSourceOpen at `{path}`", err, ) .attach_context("path", path.display().to_string()) @@ -154,7 +154,7 @@ impl<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> FileArchiver<'a, BE, I> { usize::try_from(node.meta.size).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert node size to usize", + "Failed to convert node size `{size}` to usize", err, ) .attach_context("size", node.meta.size.to_string()) diff --git a/crates/core/src/archiver/tree_archiver.rs b/crates/core/src/archiver/tree_archiver.rs index 278f02b1..df2ee52a 100644 --- a/crates/core/src/archiver/tree_archiver.rs +++ b/crates/core/src/archiver/tree_archiver.rs @@ -166,9 +166,13 @@ impl<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> TreeArchiver<'a, BE, I> { /// The id of the tree. fn backup_tree(&mut self, path: &Path, parent: &ParentResult) -> RusticResult { let (chunk, id) = self.tree.serialize().map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Failed to serialize tree.", err) - .attach_context("path", path.to_string_lossy()) - .ask_report() + RusticError::with_source( + ErrorKind::Internal, + "Failed to serialize tree at `{path}`", + err, + ) + .attach_context("path", path.to_string_lossy()) + .ask_report() })?; let dirsize = chunk.len() as u64; let dirsize_bytes = ByteSize(dirsize).to_string_as(true); diff --git a/crates/core/src/backend.rs b/crates/core/src/backend.rs index 67abe40d..2179671b 100644 --- a/crates/core/src/backend.rs +++ b/crates/core/src/backend.rs @@ -231,11 +231,14 @@ pub trait FindInBackend: ReadBackend { MapResult::Some(id) => Ok(id), MapResult::None => Err(RusticError::new( ErrorKind::Backend, - "No suitable id found.", + "No suitable id found for `{id}`.", ) - .attach_context("item", vec[i].as_ref().to_string())), - MapResult::NonUnique => Err(RusticError::new(ErrorKind::Backend, "Id not unique.") - .attach_context("item", vec[i].as_ref().to_string())), + .attach_context("id", vec[i].as_ref().to_string())), + MapResult::NonUnique => Err(RusticError::new( + ErrorKind::Backend, + "Id not unique: `{id}`.", + ) + .attach_context("id", vec[i].as_ref().to_string())), }) .collect() } diff --git a/crates/core/src/backend/cache.rs b/crates/core/src/backend/cache.rs index 4cfd4574..e8ec526e 100644 --- a/crates/core/src/backend/cache.rs +++ b/crates/core/src/backend/cache.rs @@ -245,7 +245,7 @@ impl Cache { fs::create_dir_all(&path).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to create cache directory", + "Failed to create cache directory at `{path}`", err, ) .attach_context("path", path.display().to_string()) @@ -255,7 +255,7 @@ impl Cache { cachedir::ensure_tag(&path).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to ensure cache directory tag", + "Failed to ensure cache directory tag at `{path}`", err, ) .attach_context("path", path.display().to_string()) @@ -267,7 +267,7 @@ impl Cache { fs::create_dir_all(&path).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to create cache directory with id", + "Failed to create cache directory with id `{id}` at `{path}`", err, ) .attach_context("path", path.display().to_string()) @@ -409,7 +409,7 @@ impl Cache { Err(err) if err.kind() == io::ErrorKind::NotFound => Ok(None), Err(err) => Err(RusticError::with_source( ErrorKind::InputOutput, - "Failed to read full data of file", + "Failed to read full data of file at `{path}`", err, ) .attach_context("path", path.display().to_string()) @@ -444,15 +444,18 @@ impl Cache { &offset ); - let mut file = match File::open(self.path(tpe, id)) { + let path = self.path(tpe, id); + + let mut file = match File::open(&path) { Ok(file) => file, Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(None), Err(err) => { return Err(RusticError::with_source( ErrorKind::InputOutput, - "Failed to open file", + "Failed to open file at `{path}`", err, ) + .attach_context("path", path.display().to_string()) .attach_context("tpe", tpe.to_string()) .attach_context("id", id.to_string())) } @@ -461,20 +464,29 @@ impl Cache { _ = file .seek(SeekFrom::Start(u64::from(offset))) .map_err(|err| { - RusticError::with_source(ErrorKind::InputOutput, "Failed to seek in file", err) - .attach_context("tpe", tpe.to_string()) - .attach_context("id", id.to_string()) - .attach_context("offset", offset.to_string()) + RusticError::with_source( + ErrorKind::InputOutput, + "Failed to seek to `{offset}` in file `{path}`", + err, + ) + .attach_context("path", path.display().to_string()) + .attach_context("tpe", tpe.to_string()) + .attach_context("id", id.to_string()) + .attach_context("offset", offset.to_string()) })?; let mut vec = vec![0; length as usize]; file.read_exact(&mut vec).map_err(|err| { - RusticError::with_source(ErrorKind::InputOutput, "Failed to read from file", err) - .attach_context("tpe", tpe.to_string()) - .attach_context("id", id.to_string()) - .attach_context("offset", offset.to_string()) - .attach_context("length", length.to_string()) + RusticError::with_source( + ErrorKind::InputOutput, + "Failed to read at offset `{offset}` from file at `{path}`", + err, + ) + .attach_context("tpe", tpe.to_string()) + .attach_context("id", id.to_string()) + .attach_context("offset", offset.to_string()) + .attach_context("length", length.to_string()) })?; trace!("cache hit!"); @@ -499,10 +511,14 @@ impl Cache { let dir = self.dir(tpe, id); fs::create_dir_all(&dir).map_err(|err| { - RusticError::with_source(ErrorKind::InputOutput, "Failed to create directories", err) - .attach_context("path", dir.display().to_string()) - .attach_context("tpe", tpe.to_string()) - .attach_context("id", id.to_string()) + RusticError::with_source( + ErrorKind::InputOutput, + "Failed to create directories at `{path}`", + err, + ) + .attach_context("path", dir.display().to_string()) + .attach_context("tpe", tpe.to_string()) + .attach_context("id", id.to_string()) })?; let filename = self.path(tpe, id); @@ -513,15 +529,23 @@ impl Cache { .write(true) .open(&filename) .map_err(|err| { - RusticError::with_source(ErrorKind::InputOutput, "Failed to open file", err) - .attach_context("path", filename.display().to_string()) + RusticError::with_source( + ErrorKind::InputOutput, + "Failed to open file at `{path}`", + err, + ) + .attach_context("path", filename.display().to_string()) })?; file.write_all(buf).map_err(|err| { - RusticError::with_source(ErrorKind::InputOutput, "Failed to write to buffer", err) - .attach_context("path", filename.display().to_string()) - .attach_context("tpe", tpe.to_string()) - .attach_context("id", id.to_string()) + RusticError::with_source( + ErrorKind::InputOutput, + "Failed to write to buffer at `{path}`", + err, + ) + .attach_context("path", filename.display().to_string()) + .attach_context("tpe", tpe.to_string()) + .attach_context("id", id.to_string()) })?; Ok(()) @@ -541,10 +565,14 @@ impl Cache { trace!("cache writing tpe: {:?}, id: {}", &tpe, &id); let filename = self.path(tpe, id); fs::remove_file(&filename).map_err(|err| { - RusticError::with_source(ErrorKind::InputOutput, "Failed to remove file", err) - .attach_context("path", filename.display().to_string()) - .attach_context("tpe", tpe.to_string()) - .attach_context("id", id.to_string()) + RusticError::with_source( + ErrorKind::InputOutput, + "Failed to remove file at `{path}`", + err, + ) + .attach_context("path", filename.display().to_string()) + .attach_context("tpe", tpe.to_string()) + .attach_context("id", id.to_string()) })?; Ok(()) diff --git a/crates/core/src/backend/decrypt.rs b/crates/core/src/backend/decrypt.rs index c6df00ab..414084f4 100644 --- a/crates/core/src/backend/decrypt.rs +++ b/crates/core/src/backend/decrypt.rs @@ -81,10 +81,11 @@ pub trait DecryptReadBackend: ReadBackend + Clone + 'static { err, ) })?; + if data.len() != length.get() as usize { return Err(RusticError::new( ErrorKind::Internal, - "Length of uncompressed data does not match the given length.", + "Length of uncompressed data `{actual_length}` does not match the given length `{expected_length}`.", ) .attach_context("expected_length", length.get().to_string()) .attach_context("actual_length", data.len().to_string()) @@ -423,7 +424,7 @@ impl DecryptBackend { "Compressing and appending data failed. The data may be corrupted.", err, ) - .attach_context("compression level", level.to_string()) + .attach_context("compression_level", level.to_string()) })?; self.key().encrypt_data(&out)? @@ -453,7 +454,7 @@ impl DecryptBackend { let data_len: u32 = data.len().try_into().map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert data length to u32.", + "Failed to convert data length `{length}` to u32.", err, ) .attach_context("length", data.len().to_string()) @@ -471,7 +472,7 @@ impl DecryptBackend { "Failed to encode zstd compressed data. The data may be corrupted.", err, ) - .attach_context("compression level", level.to_string()) + .attach_context("compression_level", level.to_string()) })?)?, NonZeroU32::new(data_len), ), diff --git a/crates/core/src/backend/ignore.rs b/crates/core/src/backend/ignore.rs index 1d37cf75..a3c5cf2d 100644 --- a/crates/core/src/backend/ignore.rs +++ b/crates/core/src/backend/ignore.rs @@ -192,7 +192,7 @@ impl LocalSource { _ = override_builder.add(g).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add glob pattern to override builder.", + "Failed to add glob pattern `{glob}` to override builder.", err, ) .attach_context("glob", g.to_string()) @@ -205,10 +205,10 @@ impl LocalSource { .map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to read string from glob file.", + "Failed to read string from glob file at `{glob_file}`", err, ) - .attach_context("glob file", file.to_string()) + .attach_context("glob_file", file.to_string()) .ask_report() })? .lines() @@ -216,10 +216,10 @@ impl LocalSource { _ = override_builder.add(line).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add glob pattern line to override builder.", + "Failed to add glob pattern line `{glob_pattern_line}` to override builder.", err, ) - .attach_context("glob pattern line", line.to_string()) + .attach_context("glob_pattern_line", line.to_string()) .ask_report() })?; } @@ -237,7 +237,7 @@ impl LocalSource { _ = override_builder.add(g).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add iglob pattern to override builder.", + "Failed to add iglob pattern `{iglob}` to override builder.", err, ) .attach_context("iglob", g.to_string()) @@ -250,10 +250,10 @@ impl LocalSource { .map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to read string from iglob file.", + "Failed to read string from iglob file at `{iglob_file}`", err, ) - .attach_context("iglob file", file.to_string()) + .attach_context("iglob_file", file.to_string()) .ask_report() })? .lines() @@ -261,10 +261,10 @@ impl LocalSource { _ = override_builder.add(line).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add iglob pattern line to override builder.", + "Failed to add iglob pattern line `{iglob_pattern_line}` to override builder.", err, ) - .attach_context("iglob pattern line", line.to_string()) + .attach_context("iglob_pattern_line", line.to_string()) .ask_report() })?; } @@ -334,10 +334,10 @@ impl ReadSourceOpen for OpenFile { File::open(&path).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to open file. Please make sure the file exists and is accessible.", + "Failed to open file at `{path}`. Please make sure the file exists and is accessible.", err, ) - .attach_context("file", path.display().to_string()) + .attach_context("path", path.display().to_string()) }) } } diff --git a/crates/core/src/backend/local_destination.rs b/crates/core/src/backend/local_destination.rs index 837f7d55..bef3852b 100644 --- a/crates/core/src/backend/local_destination.rs +++ b/crates/core/src/backend/local_destination.rs @@ -154,7 +154,7 @@ impl LocalDestination { fs::create_dir_all(path).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "The directory could not be created.", + "The directory `{path}` could not be created.", err, ) .attach_context("path", path.display().to_string()) @@ -164,7 +164,7 @@ impl LocalDestination { fs::create_dir_all(&path).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "The directory could not be created.", + "The directory `{path}` could not be created.", err, ) .attach_context("path", path.display().to_string()) diff --git a/crates/core/src/blob/packer.rs b/crates/core/src/blob/packer.rs index 4295434d..33a26ed4 100644 --- a/crates/core/src/blob/packer.rs +++ b/crates/core/src/blob/packer.rs @@ -301,9 +301,13 @@ impl Packer { pub fn add(&self, data: Bytes, id: BlobId) -> RusticResult<()> { // compute size limit based on total size and size bounds self.add_with_sizelimit(data, id, None).map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Failed to add blob to packfile.", err) - .attach_context("blob id", id.to_string()) - .ask_report() + RusticError::with_source( + ErrorKind::Internal, + "Failed to add blob `{id}` to packfile.", + err, + ) + .attach_context("id", id.to_string()) + .ask_report() }) } @@ -576,10 +580,10 @@ impl RawPacker { let data_len_packed: u64 = data.len().try_into().map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert data length to u64.", + "Failed to convert data length `{length}` to u64.", err, ) - .attach_context("data length", data.len().to_string()) + .attach_context("length", data.len().to_string()) })?; self.stats.data_packed += data_len_packed; @@ -591,12 +595,12 @@ impl RawPacker { let len = self.write_data(data).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to write data to packfile.", + "Failed to write data to packfile for blob `{id}`.", err, ) - .attach_context("blob id", id.to_string()) - .attach_context("size limit", size_limit.to_string()) - .attach_context("data length packed", data_len_packed.to_string()) + .attach_context("id", id.to_string()) + .attach_context("size_limit", size_limit.to_string()) + .attach_context("data_length_packed", data_len_packed.to_string()) })?; self.index @@ -636,10 +640,10 @@ impl RawPacker { .map_err(|err| -> Box { RusticError::with_source( ErrorKind::Internal, - "Failed to convert pack header to binary representation.", + "Failed to convert pack header `{index_pack_id}` to binary representation.", err, ) - .attach_context("index pack id", self.index.id.to_string()) + .attach_context("index_pack_id", self.index.id.to_string()) })?; // encrypt and write to pack file @@ -648,20 +652,20 @@ impl RawPacker { let headerlen: u32 = data.len().try_into().map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert header length to u32.", + "Failed to convert header length `{length}` to u32.", err, ) - .attach_context("header length", data.len().to_string()) + .attach_context("length", data.len().to_string()) })?; // write header to pack file _ = self.write_data(&data).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to write header to packfile.", + "Failed to write header with length `{length}` to packfile.", err, ) - .attach_context("header length", headerlen.to_string()) + .attach_context("length", headerlen.to_string()) })?; // convert header length to binary representation @@ -670,20 +674,20 @@ impl RawPacker { .map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert header length to binary representation.", + "Failed to convert header length `{length}` to binary representation.", err, ) - .attach_context("header length", headerlen.to_string()) + .attach_context("length", headerlen.to_string()) })?; // finally write length of header unencrypted to pack file _ = self.write_data(&binary_repr).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to write header length to packfile.", + "Failed to write header length `{length}` to packfile.", err, ) - .attach_context("header length", headerlen.to_string()) + .attach_context("length", headerlen.to_string()) })?; Ok(()) diff --git a/crates/core/src/blob/tree.rs b/crates/core/src/blob/tree.rs index 211e721c..e28d079d 100644 --- a/crates/core/src/blob/tree.rs +++ b/crates/core/src/blob/tree.rs @@ -134,8 +134,11 @@ impl Tree { let data = index .get_tree(&id) .ok_or_else(|| { - RusticError::new(ErrorKind::Internal, "Blob ID not found in index") - .attach_context("tree id", id.to_string()) + RusticError::new( + ErrorKind::Internal, + "Tree ID `{tree_id}` not found in index", + ) + .attach_context("tree_id", id.to_string()) })? .read_data(be)?; @@ -177,14 +180,14 @@ impl Tree { if let Some(p) = comp_to_osstr(p).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert Path component to OsString.", + "Failed to convert Path component `{path}` to OsString.", err, ) .attach_context("path", path.display().to_string()) .ask_report() })? { let id = node.subtree.ok_or_else(|| { - RusticError::new(ErrorKind::Internal, "Node is not a directory.") + RusticError::new(ErrorKind::Internal, "Node `{node}` is not a directory.") .attach_context("node", p.to_string_lossy()) .ask_report() })?; @@ -194,7 +197,7 @@ impl Tree { .into_iter() .find(|node| node.name() == p) .ok_or_else(|| { - RusticError::new(ErrorKind::Internal, "Node not found in tree.") + RusticError::new(ErrorKind::Internal, "Node `{node}` not found in tree.") .attach_context("node", p.to_string_lossy()) .ask_report() })?; @@ -236,9 +239,12 @@ impl Tree { Some(*node_idx) } else { let id = node.subtree.ok_or_else(|| { - RusticError::new(ErrorKind::Internal, "Subtree ID not found.") - .attach_context("node", path_comp[idx].to_string_lossy()) - .ask_report() + RusticError::new( + ErrorKind::Internal, + "Subtree ID not found for node `{node}`", + ) + .attach_context("node", path_comp[idx].to_string_lossy()) + .ask_report() })?; find_node_from_component( @@ -265,7 +271,7 @@ impl Tree { .map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert Path component to OsString.", + "Failed to convert Path component `{path}` to OsString.", err, ) .attach_context("path", path.display().to_string()) @@ -343,9 +349,12 @@ impl Tree { let node_path = path.join(node.name()); if node.is_dir() { let id = node.subtree.ok_or_else(|| { - RusticError::new(ErrorKind::Internal, "Subtree ID not found.") - .attach_context("node", node.name().to_string_lossy()) - .ask_report() + RusticError::new( + ErrorKind::Internal, + "Subtree ID not found for node `{node}`", + ) + .attach_context("node", node.name().to_string_lossy()) + .ask_report() })?; result.append(&mut find_matching_nodes_recursive( @@ -591,7 +600,7 @@ where _ = override_builder.add(g).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add glob pattern to override builder.", + "Failed to add glob pattern `{glob}` to override builder.", err, ) .attach_context("glob", g.to_string()) @@ -604,10 +613,10 @@ where .map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to read string from glob file.", + "Failed to read string from glob file `{glob_file}` ", err, ) - .attach_context("glob file", file.to_string()) + .attach_context("glob_file", file.to_string()) .ask_report() })? .lines() @@ -615,10 +624,10 @@ where _ = override_builder.add(line).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add glob pattern line to override builder.", + "Failed to add glob pattern line `{glob_pattern_line}` to override builder.", err, ) - .attach_context("glob pattern line", line.to_string()) + .attach_context("glob_pattern_line", line.to_string()) .ask_report() })?; } @@ -636,7 +645,7 @@ where _ = override_builder.add(g).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add iglob pattern to override builder.", + "Failed to add iglob pattern `{iglob}` to override builder.", err, ) .attach_context("iglob", g.to_string()) @@ -649,10 +658,10 @@ where .map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to read string from iglob file.", + "Failed to read string from iglob file `{iglob_file}`", err, ) - .attach_context("iglob file", file.to_string()) + .attach_context("iglob_file", file.to_string()) .ask_report() })? .lines() @@ -660,10 +669,10 @@ where _ = override_builder.add(line).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add iglob pattern line to override builder.", + "Failed to add iglob pattern line `{iglob_pattern_line}` to override builder.", err, ) - .attach_context("iglob pattern line", line.to_string()) + .attach_context("iglob_pattern_line", line.to_string()) .ask_report() })?; } @@ -806,10 +815,10 @@ impl TreeStreamerOnce

{ .map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add tree ID to pending queue.", + "Failed to add tree ID `{tree_id}` to unbounded pending queue (`{count}`).", err, ) - .attach_context("tree id", id.to_string()) + .attach_context("tree_id", id.to_string()) .attach_context("count", count.to_string()) .ask_report() })? @@ -874,7 +883,7 @@ impl Iterator for TreeStreamerOnce

{ "Failed to receive tree from crossbeam channel.", err, ) - .attach_context("finished ids", self.finished_ids.to_string()) + .attach_context("finished_ids", self.finished_ids.to_string()) .ask_report())); } Ok(Err(err)) => return Some(Err(err)), @@ -890,11 +899,11 @@ impl Iterator for TreeStreamerOnce

{ return Some(Err(err).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to add tree ID to pending queue.", + "Failed to add tree ID `{tree_id}` to pending queue (`{count}`).", err, ) .attach_context("path", path.display().to_string()) - .attach_context("tree id", id.to_string()) + .attach_context("tree_id", id.to_string()) .attach_context("count", count.to_string()) .ask_report() })) diff --git a/crates/core/src/commands/backup.rs b/crates/core/src/commands/backup.rs index dd999189..0b7e6602 100644 --- a/crates/core/src/commands/backup.rs +++ b/crates/core/src/commands/backup.rs @@ -205,6 +205,7 @@ pub struct BackupOptions { /// # Returns /// /// The snapshot pointing to the backup'ed data. +#[allow(clippy::too_many_lines)] pub(crate) fn backup( repo: &Repository, opts: &BackupOptions, @@ -228,7 +229,7 @@ pub(crate) fn backup( .map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Failed to parse dotted path.", + "Failed to parse dotted path `{path}`", err, ) .attach_context("path", p.display().to_string()) @@ -239,19 +240,27 @@ pub(crate) fn backup( match &as_path { Some(p) => snap.paths.set_paths(&[p.clone()]).map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Failed to set paths in snapshot.", err) - .attach_context("paths", p.display().to_string()) + RusticError::with_source( + ErrorKind::Internal, + "Failed to set paths `{paths}` in snapshot.", + err, + ) + .attach_context("paths", p.display().to_string()) })?, None => snap.paths.set_paths(&backup_path).map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Failed to set paths in snapshot.", err) - .attach_context( - "paths", - backup_path - .iter() - .map(|p| p.display().to_string()) - .collect::>() - .join(","), - ) + RusticError::with_source( + ErrorKind::Internal, + "Failed to set paths `{paths}` in snapshot.", + err, + ) + .attach_context( + "paths", + backup_path + .iter() + .map(|p| p.display().to_string()) + .collect::>() + .join(","), + ) })?, }; diff --git a/crates/core/src/commands/cat.rs b/crates/core/src/commands/cat.rs index 8d355ea8..ae4a8cb1 100644 --- a/crates/core/src/commands/cat.rs +++ b/crates/core/src/commands/cat.rs @@ -107,7 +107,7 @@ pub(crate) fn cat_tree( let id = node.subtree.ok_or_else(|| { RusticError::new( ErrorKind::Command, - "Path in Node subtree is not a directory. Please provide a directory path.", + "Path `{path}` in Node subtree is not a directory. Please provide a directory path.", ) .attach_context("path", path.to_string()) })?; diff --git a/crates/core/src/commands/check.rs b/crates/core/src/commands/check.rs index 7d57d65f..242bea9b 100644 --- a/crates/core/src/commands/check.rs +++ b/crates/core/src/commands/check.rs @@ -149,7 +149,7 @@ impl FromStr for ReadSubsetOption { let percentage = p.parse().map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Error parsing percentage for ReadSubset option. Did you forget the '%'?", + "Error parsing percentage from value `{value}` for ReadSubset option. Did you forget the '%'?", err, ) .attach_context("value", p.to_string()) @@ -162,7 +162,7 @@ impl FromStr for ReadSubsetOption { |err| RusticError::with_source( ErrorKind::InvalidInput, - "Error parsing n/m for ReadSubset option. Allowed values: 'all', 'x%', 'n/m' or a size.", + "Error parsing 'n/m' from value `{value}` for ReadSubset option. Allowed values: 'all', 'x%', 'n/m' or a size.", err ) .attach_context("value", s) @@ -176,7 +176,7 @@ impl FromStr for ReadSubsetOption { .map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Error parsing size for ReadSubset option. Allowed values: 'all', 'x%', 'n/m' or a size.", + "Error parsing size from value `{value}` for ReadSubset option. Allowed values: 'all', 'x%', 'n/m' or a size.", err ) .attach_context("value", s) @@ -689,10 +689,14 @@ fn check_pack( let header_len = PackHeaderRef::from_index_pack(&index_pack).size(); let pack_header_len = PackHeaderLength::from_binary(&data.split_off(data.len() - 4)) .map_err(|err| { - RusticError::with_source(ErrorKind::Command, "Error reading pack header length.", err) - .attach_context("pack id", id.to_string()) - .attach_context("header length", header_len.to_string()) - .ask_report() + RusticError::with_source( + ErrorKind::Command, + "Error reading pack header length `{length}` for `{pack_id}`", + err, + ) + .attach_context("pack_id", id.to_string()) + .attach_context("length", header_len.to_string()) + .ask_report() })? .to_u32(); if pack_header_len != header_len { @@ -705,9 +709,13 @@ fn check_pack( let pack_blobs = PackHeader::from_binary(&header) .map_err(|err| { - RusticError::with_source(ErrorKind::Command, "Error reading pack header.", err) - .attach_context("pack id", id.to_string()) - .ask_report() + RusticError::with_source( + ErrorKind::Command, + "Error reading pack header for id `{pack_id}`", + err, + ) + .attach_context("pack_id", id.to_string()) + .ask_report() })? .into_blobs(); let mut blobs = index_pack.blobs; diff --git a/crates/core/src/commands/config.rs b/crates/core/src/commands/config.rs index 24adafab..fa6c0065 100644 --- a/crates/core/src/commands/config.rs +++ b/crates/core/src/commands/config.rs @@ -192,17 +192,17 @@ impl ConfigOptions { if !range.contains(&version) { return Err(RusticError::new( ErrorKind::Unsupported, - "Config version not supported.", + "Config version unsupported. Allowed versions are `{allowed_versions}`. You provided `{current_version}`. Please use a supported version. ", ) - .attach_context("current version", version.to_string()) - .attach_context("allowed versions", format!("{range:?}"))); + .attach_context("current_version", version.to_string()) + .attach_context("allowed_versions", format!("{range:?}"))); } else if version < config.version { return Err(RusticError::new( ErrorKind::Unsupported, - "Downgrading config version is not supported. Please use a higher version.", + "Downgrading config version is unsupported. You provided `{new_version}` which is smaller than `{current_version}`. Please use a version that is greater or equal to the current one.", ) - .attach_context("current version", config.version.to_string()) - .attach_context("new version", version.to_string())); + .attach_context("current_version", config.version.to_string()) + .attach_context("new_version", version.to_string())); } config.version = version; @@ -212,7 +212,7 @@ impl ConfigOptions { if config.version == 1 && compression != 0 { return Err(RusticError::new( ErrorKind::Unsupported, - "Compression not supported for v1 repos.", + "Compression `{compression}` unsupported for v1 repos.", ) .attach_context("compression", compression.to_string())); } @@ -221,10 +221,10 @@ impl ConfigOptions { if !range.contains(&compression) { return Err(RusticError::new( ErrorKind::Unsupported, - "Compression level not supported.", + "Compression level `{compression}` is unsupported. Allowed levels are `{allowed_levels}`. Please use a supported level.", ) .attach_context("compression", compression.to_string()) - .attach_context("allowed levels", format!("{range:?}"))); + .attach_context("allowed_levels", format!("{range:?}"))); } config.compression = Some(compression); } @@ -273,7 +273,7 @@ impl ConfigOptions { if percent > 100 { return Err(RusticError::new( ErrorKind::InvalidInput, - "`min_packsize_tolerate_percent` must be <= 100.", + "`min_packsize_tolerate_percent` must be <= 100. You provided `{percent}`.", ) .attach_context("percent", percent.to_string())); } @@ -285,7 +285,7 @@ impl ConfigOptions { if percent < 100 && percent > 0 { return Err(RusticError::new( ErrorKind::InvalidInput, - "`max_packsize_tolerate_percent` must be >= 100 or 0.", + "`max_packsize_tolerate_percent` must be >= 100 or 0. You provided `{percent}`.", ) .attach_context("percent", percent.to_string())); } @@ -304,7 +304,7 @@ fn construct_size_too_large_error( ) -> Box { RusticError::with_source( ErrorKind::Internal, - "Failed to convert ByteSize to u64. Size is too large.", + "Failed to convert ByteSize `{size}` to u64. Size is too large.", err, ) .attach_context("size", size.to_string()) diff --git a/crates/core/src/commands/dump.rs b/crates/core/src/commands/dump.rs index 5725a2f5..dac2f347 100644 --- a/crates/core/src/commands/dump.rs +++ b/crates/core/src/commands/dump.rs @@ -31,9 +31,9 @@ pub(crate) fn dump( if node.node_type != NodeType::File { return Err(RusticError::new( ErrorKind::Unsupported, - "Dump is not supported for non-file node types. You could try to use `cat` instead.", + "Dump is not supported for non-file node types `{node_type}`. You could try to use `cat` instead.", ) - .attach_context("node type", node.node_type.to_string())); + .attach_context("node_type", node.node_type.to_string())); } for id in node.content.as_ref().unwrap() { diff --git a/crates/core/src/commands/merge.rs b/crates/core/src/commands/merge.rs index b4a68ac5..10d15dd1 100644 --- a/crates/core/src/commands/merge.rs +++ b/crates/core/src/commands/merge.rs @@ -45,8 +45,12 @@ pub(crate) fn merge_snapshots( .merge(); snap.paths.set_paths(&paths.paths()).map_err(|err| { - RusticError::with_source(ErrorKind::Internal, "Failed to set paths in snapshot.", err) - .attach_context("paths", paths.to_string()) + RusticError::with_source( + ErrorKind::Internal, + "Failed to set paths `{paths}` in snapshot.", + err, + ) + .attach_context("paths", paths.to_string()) })?; // set snapshot time to time of latest snapshot to be merged @@ -116,10 +120,10 @@ pub(crate) fn merge_trees( let size = u64::try_from(chunk.len()).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert chunk length to u64.", + "Failed to convert chunk length `{length}` to u64.", err, ) - .attach_context("chunk length", chunk.len().to_string()) + .attach_context("length", chunk.len().to_string()) })?; if !index.has_tree(&new_id) { diff --git a/crates/core/src/commands/prune.rs b/crates/core/src/commands/prune.rs index a375d7f5..56ee7a73 100644 --- a/crates/core/src/commands/prune.rs +++ b/crates/core/src/commands/prune.rs @@ -203,7 +203,7 @@ impl FromStr for LimitOption { copy.parse().map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Failed to parse percentage limit.", + "Failed to parse percentage limit `{limit}`", err, ) .attach_context("limit", s) @@ -214,7 +214,7 @@ impl FromStr for LimitOption { let byte_size = ByteSize::from_str(s).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Failed to parse size limit.", + "Failed to parse size limit `{limit}`", err, ) .attach_context("limit", s) @@ -704,9 +704,9 @@ impl PrunePlan { if version < 2 && opts.repack_uncompressed { return Err(RusticError::new( ErrorKind::Unsupported, - "Repacking uncompressed pack is unsupported in Repository version 1.", + "Repacking uncompressed pack is unsupported in Repository version `{config_version}`.", ) - .attach_context("config version", version.to_string())); + .attach_context("config_version", version.to_string())); } let mut index_files = Vec::new(); @@ -754,7 +754,7 @@ impl PrunePlan { Duration::from_std(*opts.keep_pack).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert keep_pack duration to std::time::Duration.", + "Failed to convert keep_pack duration `{keep_pack}` to std::time::Duration.", err, ) .attach_context("keep_pack", opts.keep_pack.to_string()) @@ -762,7 +762,7 @@ impl PrunePlan { Duration::from_std(*opts.keep_delete).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert keep_delete duration to std::time::Duration.", + "Failed to convert keep_delete duration `{keep_delete}` to std::time::Duration.", err, ) .attach_context("keep_delete", opts.keep_delete.to_string()) @@ -814,9 +814,9 @@ impl PrunePlan { if *count == 0 { return Err(RusticError::new( ErrorKind::Command, - "Blob is missing in index files.", + "Blob ID `{blob_id}` is missing in index files.", ) - .attach_context("blob id", id.to_string()) + .attach_context("blob_id", id.to_string()) .ask_report()); } } @@ -1085,14 +1085,14 @@ impl PrunePlan { Some(size) if size == pack.size => Ok(()), // size is ok => continue Some(size) => Err(RusticError::new( ErrorKind::Command, - "Pack size does not match the size in the index file.", + "Pack size `{size_in_pack_real}` of id `{pack_id}` does not match the expected size `{size_in_index_expected}` in the index file. ", ) - .attach_context("pack id", pack.id.to_string()) - .attach_context("size in index (expected)", pack.size.to_string()) - .attach_context("size in pack (real)", size.to_string()) + .attach_context("pack_id", pack.id.to_string()) + .attach_context("size_in_index_expected", pack.size.to_string()) + .attach_context("size_in_pack_real", size.to_string()) .ask_report()), - None => Err(RusticError::new(ErrorKind::Command, "Pack does not exist.") - .attach_context("pack id", pack.id.to_string()) + None => Err(RusticError::new(ErrorKind::Command, "Pack `{pack_id}` does not exist.") + .attach_context("pack_id", pack.id.to_string()) .ask_report()), } }; @@ -1101,9 +1101,9 @@ impl PrunePlan { PackToDo::Undecided => { return Err(RusticError::new( ErrorKind::Command, - "Pack got no decision what to do with it!", + "Pack `{pack_id}` got no decision what to do with it!", ) - .attach_context("pack id", pack.id.to_string()) + .attach_context("pack_id", pack.id.to_string()) .ask_report()); } PackToDo::Keep | PackToDo::Recover => { @@ -1354,9 +1354,9 @@ pub(crate) fn prune_repository( PackToDo::Undecided => { return Err(RusticError::new( ErrorKind::Command, - "Pack got no decision what to do with it!", + "Pack `{pack_id}` got no decision what to do with it!", ) - .attach_context("pack id", pack.id.to_string()) + .attach_context("pack_id", pack.id.to_string()) .ask_report()); } PackToDo::Keep => { diff --git a/crates/core/src/commands/repair/index.rs b/crates/core/src/commands/repair/index.rs index a869cf81..4ff7dc2f 100644 --- a/crates/core/src/commands/repair/index.rs +++ b/crates/core/src/commands/repair/index.rs @@ -81,13 +81,10 @@ pub(crate) fn repair_index( p.set_length(pack_read_header.len().try_into().map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert pack_read_header length to u64.", + "Failed to convert `pack_read_header` length `{length}` to u64.", err, ) - .attach_context( - "pack read header length", - pack_read_header.len().to_string(), - ) + .attach_context("length", pack_read_header.len().to_string()) })?); for (id, size_hint, packsize) in pack_read_header { debug!("reading pack {id}..."); @@ -199,13 +196,10 @@ pub(crate) fn index_checked_from_collector( p.set_length(pack_read_header.len().try_into().map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert pack_read_header length to u64.", + "Failed to convert `pack_read_header` length `{length}` to u64.", err, ) - .attach_context( - "pack read header length", - pack_read_header.len().to_string(), - ) + .attach_context("length", pack_read_header.len().to_string()) })?); let index_packs: Vec<_> = pack_read_header diff --git a/crates/core/src/commands/restore.rs b/crates/core/src/commands/restore.rs index 04b35f72..6d8e029f 100644 --- a/crates/core/src/commands/restore.rs +++ b/crates/core/src/commands/restore.rs @@ -223,7 +223,7 @@ pub(crate) fn collect_and_prepare( .map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to create the directory. Please check the path and try again.", + "Failed to create the directory `{path}`. Please check the path and try again.", err ) .attach_context("path", path.display().to_string()) @@ -454,7 +454,7 @@ fn restore_contents( dest.set_length(path, *size).map_err(|err| { RusticError::with_source( ErrorKind::InputOutput, - "Failed to set the length of the file. Please check the path and try again.", + "Failed to set the length of the file `{path}`. Please check the path and try again.", err, ) .attach_context("path", path.display().to_string()) @@ -507,10 +507,10 @@ fn restore_contents( .map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to create the thread pool. Please try again.", + "Failed to create the thread pool with `{num_threads}` threads. Please try again.", err, ) - .attach_context("num threads", threads.to_string()) + .attach_context("num_threads", threads.to_string()) })?; pool.in_place_scope(|s| { @@ -679,7 +679,7 @@ impl RestorePlan { .map_err(|err| RusticError::with_source( ErrorKind::InputOutput, - "Failed to get the metadata of the file. Please check the path and try again.", + "Failed to get the metadata of the file `{path}`. Please check the path and try again.", err ) .attach_context("path", name.display().to_string()) @@ -700,7 +700,7 @@ impl RestorePlan { .map_err(|err| RusticError::with_source( ErrorKind::InputOutput, - "Failed to get the metadata of the file. Please check the path and try again.", + "Failed to get the metadata of the file `{path}`. Please check the path and try again.", err ) .attach_context("path", name.display().to_string()) @@ -736,7 +736,7 @@ impl RestorePlan { let usize_length = usize::try_from(length).map_err(|err| { RusticError::with_source( ErrorKind::Internal, - "Failed to convert the length to usize. Please try again.", + "Failed to convert the length `{length}` to usize. Please try again.", err, ) .attach_context("length", length.to_string()) diff --git a/crates/core/src/id.rs b/crates/core/src/id.rs index acd4a2b1..856cab24 100644 --- a/crates/core/src/id.rs +++ b/crates/core/src/id.rs @@ -88,7 +88,7 @@ impl FromStr for Id { hex::decode_to_slice(s, &mut id.0).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Failed to decode hex string into Id. The value must be a valid hexadecimal string.", + "Failed to decode hex string `{value}` into Id. The value must be a valid hexadecimal string.", err ) .attach_context("value", s) diff --git a/crates/core/src/index.rs b/crates/core/src/index.rs index 65d13940..4251d2ff 100644 --- a/crates/core/src/index.rs +++ b/crates/core/src/index.rs @@ -184,11 +184,12 @@ pub trait ReadIndex { ) -> RusticResult { self.get_id(tpe, id).map_or_else( || { - Err( - RusticError::new(ErrorKind::Internal, "Blob not found in index") - .attach_context("blob id", id.to_string()) - .attach_context("blob type", tpe.to_string()), + Err(RusticError::new( + ErrorKind::Internal, + "Blob `{id}` with type `{type}` not found in index", ) + .attach_context("id", id.to_string()) + .attach_context("type", tpe.to_string())) }, |ie| ie.read_data(be), ) diff --git a/crates/core/src/repofile/configfile.rs b/crates/core/src/repofile/configfile.rs index 3f157718..52e4d11b 100644 --- a/crates/core/src/repofile/configfile.rs +++ b/crates/core/src/repofile/configfile.rs @@ -140,7 +140,7 @@ impl ConfigFile { let chunker_poly = u64::from_str_radix(&self.chunker_polynomial, 16) .map_err(|err| RusticError::with_source( ErrorKind::InvalidInput, - "Parsing u64 from hex failed for polynomial, the value must be a valid hexadecimal string.", + "Parsing u64 from hex failed for polynomial `{polynomial}`, the value must be a valid hexadecimal string.", err) .attach_context("polynomial",self.chunker_polynomial.to_string())) ?; @@ -160,7 +160,7 @@ impl ConfigFile { (2, Some(c)) => Ok(Some(c)), _ => Err(RusticError::new( ErrorKind::Unsupported, - "Config version not supported. Please make sure, that you use the correct version.", + "Config version `{version}` not supported. Please make sure, that you use the correct version.", ) .attach_context("version", self.version.to_string())), } diff --git a/crates/core/src/repofile/keyfile.rs b/crates/core/src/repofile/keyfile.rs index c9aabe0c..ce134aa1 100644 --- a/crates/core/src/repofile/keyfile.rs +++ b/crates/core/src/repofile/keyfile.rs @@ -256,10 +256,10 @@ impl KeyFile { serde_json::from_slice(&data).map_err(|err| { RusticError::with_source( ErrorKind::Key, - "Couldn't deserialize the data for key.", + "Couldn't deserialize the data for key `{key_id}`.", err, ) - .attach_context("key id", id.to_string()) + .attach_context("key_id", id.to_string()) }) } } diff --git a/crates/core/src/repofile/packfile.rs b/crates/core/src/repofile/packfile.rs index b0577295..c0202ad6 100644 --- a/crates/core/src/repofile/packfile.rs +++ b/crates/core/src/repofile/packfile.rs @@ -285,12 +285,13 @@ impl PackHeader { trace!("header size: {size_real}"); if size_real + constants::LENGTH_LEN > pack_size { - return Err( - RusticError::new(ErrorKind::Internal, "Read header length is too large!") - .attach_context("size real", size_real.to_string()) - .attach_context("pack size", pack_size.to_string()) - .attach_context("length field value", constants::LENGTH_LEN.to_string()), - ); + return Err(RusticError::new( + ErrorKind::Internal, + "Read header length `{size_real}` + `{length}` is larger than `{pack_size}`!", + ) + .attach_context("size_real", size_real.to_string()) + .attach_context("pack_size", pack_size.to_string()) + .attach_context("length", constants::LENGTH_LEN.to_string())); } // now read the header @@ -312,17 +313,17 @@ impl PackHeader { ErrorKind::Internal, "Read header length doesn't match header contents!", ) - .attach_context("size real", size_real.to_string()) - .attach_context("size computed", header.size().to_string())); + .attach_context("size_real", size_real.to_string()) + .attach_context("size_computed", header.size().to_string())); } if header.pack_size() != pack_size { return Err(RusticError::new( ErrorKind::Internal, - "pack size computed from header doesn't match real pack file size!", + "pack size `{size_computed}` computed from header doesn't match real pack file size `{size_real}`!", ) - .attach_context("size real", pack_size.to_string()) - .attach_context("size computed", header.pack_size().to_string())); + .attach_context("size_real", pack_size.to_string()) + .attach_context("size_computed", header.pack_size().to_string())); } Ok(header) diff --git a/crates/core/src/repofile/snapshotfile.rs b/crates/core/src/repofile/snapshotfile.rs index bc8489cb..ec7eecc6 100644 --- a/crates/core/src/repofile/snapshotfile.rs +++ b/crates/core/src/repofile/snapshotfile.rs @@ -136,7 +136,7 @@ impl SnapshotOptions { self.tags.push(StringList::from_str(tag).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Failed to create string list from tag. The value must be a valid unicode string.", + "Failed to create string list from tag `{tag}`. The value must be a valid unicode string.", err, ) .attach_context("tag", tag) @@ -390,7 +390,7 @@ impl SnapshotFile { .ok_or_else(|| { RusticError::new( ErrorKind::InvalidInput, - "Failed to convert hostname to string. The value must be a valid unicode string.", + "Failed to convert hostname `{hostname}` to string. The value must be a valid unicode string.", ) .attach_context("hostname", hostname.to_string_lossy().to_string()) })? @@ -405,7 +405,7 @@ impl SnapshotFile { time + Duration::from_std(*duration).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Failed to convert duration to std::time::Duration. Please make sure the value is a valid duration string.", + "Failed to convert duration `{duration}` to std::time::Duration. Please make sure the value is a valid duration string.", err, ) .attach_context("duration", duration.to_string()) @@ -442,7 +442,7 @@ impl SnapshotFile { snap.description = Some(std::fs::read_to_string(path).map_err(|err| { RusticError::with_source( ErrorKind::InvalidInput, - "Failed to read description file. Please make sure the file exists and is readable.", + "Failed to read description file `{path}`. Please make sure the file exists and is readable.", err, ) .attach_context("path", path.to_string_lossy().to_string()) diff --git a/crates/core/src/repository.rs b/crates/core/src/repository.rs index 98545529..bc9b4959 100644 --- a/crates/core/src/repository.rs +++ b/crates/core/src/repository.rs @@ -185,7 +185,7 @@ impl RepositoryOptions { let mut file = BufReader::new(File::open(file).map_err(|err| { RusticError::with_source( ErrorKind::Password, - "Opening password file failed. Is the path correct?", + "Opening password file failed. Is the path `{path}` correct?", err, ) .attach_context("path", file.display().to_string()) @@ -205,7 +205,7 @@ impl RepositoryOptions { error!("password-command could not be executed: {}", err); return Err(RusticError::with_source( ErrorKind::Password, - "Password command could not be executed.", + "Password command `{command}` could not be executed", err, ) .attach_context("command", command.to_string())); @@ -215,10 +215,10 @@ impl RepositoryOptions { let output = match process.wait_with_output() { Ok(output) => output, Err(err) => { - error!("error reading output from password-command: {}", err); + error!("error reading output from password-command: {err}"); return Err(RusticError::with_source( ErrorKind::Password, - "Error reading output from password command.", + "Error reading output from password command `{command}`", err, ) .attach_context("command", command.to_string())); @@ -234,7 +234,7 @@ impl RepositoryOptions { error!("password-command {s}"); return Err(RusticError::new( ErrorKind::Password, - "Password command did not exit successfully.", + "Password command `{command}` did not exit successfully: `{status}`", ) .attach_context("command", command.to_string()) .attach_context("status", s)); @@ -360,7 +360,7 @@ impl

Repository { if warm_up.args().iter().all(|c| !c.contains("%id")) { return Err(RusticError::new( ErrorKind::Command, - "No `%id` specified in warm-up command. Please specify `%id` in the command.", + "No `%id` specified in warm-up command `{command}`. Please specify `%id` in the command.", ) .attach_context("command", warm_up.to_string())); } @@ -425,7 +425,7 @@ impl Repository { 0 => Ok(None), _ => Err(RusticError::new( ErrorKind::Configuration, - "More than one repository found. Please check the config file.", + "More than one repository found for `{name}`. Please check the config file.", ) .attach_context("name", self.name.clone())), } @@ -484,7 +484,7 @@ impl Repository { let config_id = self.config_id()?.ok_or_else(|| { RusticError::new( ErrorKind::Configuration, - "No repository config file found. Please check the repository.", + "No repository config file found for `{name}`. Please check the repository.", ) .attach_context("name", self.name.clone()) })?; @@ -497,7 +497,7 @@ impl Repository { if keys != hot_keys { return Err(RusticError::new( ErrorKind::Key, - "Keys of hot and cold repositories don't match. Please check the keys.", + "Keys of hot and cold repositories don't match for `{name}`. Please check the keys.", ) .attach_context("name", self.name.clone())); } @@ -541,7 +541,7 @@ impl Repository { let password = self.password()?.ok_or_else(|| { RusticError::new( ErrorKind::Password, - "No password given, or Password was empty. Please specify a valid password.", + "No password given, or Password was empty. Please specify a valid password for `{name}`.", ) .attach_context("name", self.name.clone()) })?; @@ -577,7 +577,7 @@ impl Repository { if self.config_id()?.is_some() { return Err(RusticError::new( ErrorKind::Configuration, - "Config file already exists. Please check the repository.", + "Config file already exists for `{name}`. Please check the repository.", ) .attach_context("name", self.name)); } @@ -1567,9 +1567,9 @@ impl Repository { let ie = self.index().get_id(T::TYPE, &blob_id).ok_or_else(|| { RusticError::new( ErrorKind::Internal, - "BlobID not found in index, but should be there.", + "Blob ID `{id}` not found in index, but should be there.", ) - .attach_context("blob id", blob_id.to_string()) + .attach_context("id", blob_id.to_string()) .ask_report() })?; diff --git a/crates/core/src/repository/warm_up.rs b/crates/core/src/repository/warm_up.rs index 5621570b..22131a92 100644 --- a/crates/core/src/repository/warm_up.rs +++ b/crates/core/src/repository/warm_up.rs @@ -98,7 +98,7 @@ fn warm_up_command( .map_err(|err| { RusticError::with_source( ErrorKind::ExternalCommand, - "Error in executing warm-up command.", + "Error in executing warm-up command `{command}`.", err, ) .attach_context("command", command.to_string()) diff --git a/crates/core/src/vfs.rs b/crates/core/src/vfs.rs index cf7056a3..9a1c9d1c 100644 --- a/crates/core/src/vfs.rs +++ b/crates/core/src/vfs.rs @@ -273,7 +273,7 @@ impl Vfs { .map_err(|err| { RusticError::with_source( ErrorKind::Vfs, - "Failed to add a link to root tree.", + "Failed to add a link `{name}` to root tree at `{path}`", err, ) .attach_context("path", path.display().to_string()) @@ -286,11 +286,11 @@ impl Vfs { .map_err(|err| { RusticError::with_source( ErrorKind::Vfs, - "Failed to add repository tree to root tree.", + "Failed to add repository tree `{tree_id}` to root tree at `{path}`", err, ) .attach_context("path", path.display().to_string()) - .attach_context("tree id", snap.tree.to_string()) + .attach_context("tree_id", snap.tree.to_string()) .ask_report() })?; } @@ -311,12 +311,12 @@ impl Vfs { .map_err(|err| { RusticError::with_source( ErrorKind::Vfs, - "Failed to link latest entries to root tree.", + "Failed to link latest `{target}` entry to root tree at `{path}`", err, ) - .attach_context("latest", "link") .attach_context("path", path.display().to_string()) .attach_context("target", target.to_string_lossy()) + .attach_context("latest", "link") .ask_report() })?; } @@ -330,12 +330,12 @@ impl Vfs { .map_err(|err| { RusticError::with_source( ErrorKind::Vfs, - "Failed to add latest subtree to root tree.", + "Failed to add latest subtree id `{id}` to root tree at `{path}`", err, ) - .attach_context("latest", "dir") .attach_context("path", path.display().to_string()) - .attach_context("tree id", subtree.to_string()) + .attach_context("tree_id", subtree.to_string()) + .attach_context("latest", "dir") .ask_report() })?; } @@ -368,9 +368,13 @@ impl Vfs { ) -> RusticResult { let meta = Metadata::default(); match self.tree.get_path(path).map_err(|err| { - RusticError::with_source(ErrorKind::Vfs, "Failed to get tree at given path.", err) - .attach_context("path", path.display().to_string()) - .ask_report() + RusticError::with_source( + ErrorKind::Vfs, + "Failed to get tree at given path `{path}`", + err, + ) + .attach_context("path", path.display().to_string()) + .ask_report() })? { VfsPath::RusticPath(tree_id, path) => Ok(repo.node_from_path(*tree_id, &path)?), VfsPath::VirtualTree(_) => { @@ -414,9 +418,13 @@ impl Vfs { path: &Path, ) -> RusticResult> { let result = match self.tree.get_path(path).map_err(|err| { - RusticError::with_source(ErrorKind::Vfs, "Failed to get tree at given path.", err) - .attach_context("path", path.display().to_string()) - .ask_report() + RusticError::with_source( + ErrorKind::Vfs, + "Failed to get tree at given path `{path}`", + err, + ) + .attach_context("path", path.display().to_string()) + .ask_report() })? { VfsPath::RusticPath(tree_id, path) => { let node = repo.node_from_path(*tree_id, &path)?; @@ -440,7 +448,7 @@ impl Vfs { VfsPath::Link(str) => { return Err(RusticError::new( ErrorKind::Vfs, - "No directory entries for symlink found. Is the path valid unicode?", + "No directory entries for symlink `{symlink}` found. Is the path valid unicode?", ) .attach_context("symlink", str.to_string_lossy().to_string())); } diff --git a/crates/testing/src/backend.rs b/crates/testing/src/backend.rs index 26dbc4fd..418bd320 100644 --- a/crates/testing/src/backend.rs +++ b/crates/testing/src/backend.rs @@ -73,8 +73,10 @@ pub mod in_memory_backend { buf: Bytes, ) -> RusticResult<()> { if self.0.write().unwrap()[tpe].insert(*id, buf).is_some() { - return Err(RusticError::new(ErrorKind::Backend, "Id already exists.") - .attach_context("id", id.to_string())); + return Err( + RusticError::new(ErrorKind::Backend, "ID `{id}` already exists.") + .attach_context("id", id.to_string()), + ); } Ok(()) @@ -82,8 +84,10 @@ pub mod in_memory_backend { fn remove(&self, tpe: FileType, id: &Id, _cacheable: bool) -> RusticResult<()> { if self.0.write().unwrap()[tpe].remove(id).is_none() { - return Err(RusticError::new(ErrorKind::Backend, "Id does not exist.") - .attach_context("id", id.to_string())); + return Err( + RusticError::new(ErrorKind::Backend, "ID `{id}` does not exist.") + .attach_context("id", id.to_string()), + ); } Ok(()) }