From 9c2892fe6d888ad8c96a0716d2a71acde66fd854 Mon Sep 17 00:00:00 2001 From: Michael Weiss Date: Thu, 9 Jan 2025 20:58:46 +0100 Subject: [PATCH] Fix all clippy warnings (beta toolchain version 1.85.0-beta.1) The improved `useless_conversion` lint [0] found quite a few cases of unnecessary conversions (basically all `map_err(anyhow::Error::from)` calls except one unnecessary instance of `map(Vec::from)`). The pretty new `literal_string_with_formatting_args` lint [1] also got improved to discover a formatting string that we don't evaluate. This is a false positive though as we pass it to `indicatif::ProgressBars` as `bar_template` string. [0]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion [1]: https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args Signed-off-by: Michael Weiss --- src/commands/db.rs | 16 ++++++++-------- src/commands/endpoint.rs | 1 - src/commands/release.rs | 1 - src/commands/source/download.rs | 3 +-- src/commands/util.rs | 2 -- src/config/util.rs | 3 +++ src/db/models/githash.rs | 1 - src/db/models/job.rs | 1 - src/db/models/submit.rs | 1 - src/endpoint/configured.rs | 13 +------------ src/endpoint/scheduler.rs | 4 +--- src/filestore/path.rs | 2 -- src/filestore/staging.rs | 2 -- src/package/script.rs | 17 +++++++---------- src/package/version.rs | 2 -- src/repository/fs/representation.rs | 1 - src/source/mod.rs | 2 -- 17 files changed, 21 insertions(+), 51 deletions(-) diff --git a/src/commands/db.rs b/src/commands/db.rs index b21f5f4e..fc9cd54c 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -95,12 +95,12 @@ fn cli(db_connection_config: DbConnectionConfig<'_>, matches: &ArgMatches) -> Re info!("psql exited successfully"); Ok(()) } else { - Err(anyhow!("psql did not exit successfully")) - .with_context(|| match String::from_utf8(out.stderr) { + Err(anyhow!("psql did not exit successfully")).with_context(|| { + match String::from_utf8(out.stderr) { Ok(log) => anyhow!("{}", log), Err(e) => anyhow!("Cannot parse log into valid UTF-8: {}", e), - }) - .map_err(Error::from) + } + }) } }) } @@ -127,12 +127,12 @@ fn cli(db_connection_config: DbConnectionConfig<'_>, matches: &ArgMatches) -> Re info!("pgcli exited successfully"); Ok(()) } else { - Err(anyhow!("pgcli did not exit successfully")) - .with_context(|| match String::from_utf8(out.stderr) { + Err(anyhow!("pgcli did not exit successfully")).with_context(|| { + match String::from_utf8(out.stderr) { Ok(log) => anyhow!("{}", log), Err(e) => anyhow!("Cannot parse log into valid UTF-8: {}", e), - }) - .map_err(Error::from) + } + }) } }) } diff --git a/src/commands/endpoint.rs b/src/commands/endpoint.rs index aebb7ea3..e6705183 100644 --- a/src/commands/endpoint.rs +++ b/src/commands/endpoint.rs @@ -385,7 +385,6 @@ async fn containers_top( .top(None) .await .with_context(|| anyhow!("Fetching 'top' for {}", stat.id)) - .map_err(Error::from) .map(|top| (stat.id, top)) }) .collect::>() diff --git a/src/commands/release.rs b/src/commands/release.rs index ac950efb..eec0c974 100644 --- a/src/commands/release.rs +++ b/src/commands/release.rs @@ -203,7 +203,6 @@ async fn new_release( .with_context(|| { anyhow!("Copying {} to {}", art_path.display(), dest_path.display()) }) - .map_err(Error::from) .and_then(|_| { debug!("Updating {:?} to set released = true", art); let rel = crate::db::models::Release::create( diff --git a/src/commands/source/download.rs b/src/commands/source/download.rs index c0520c1b..444f1c59 100644 --- a/src/commands/source/download.rs +++ b/src/commands/source/download.rs @@ -246,8 +246,7 @@ pub async fn download( "Cannot download source that is marked for manual download" )) .context(anyhow!("Creating source: {}", source.path().display())) - .context(anyhow!("Downloading source: {}", source.url())) - .map_err(Error::from); + .context(anyhow!("Downloading source: {}", source.url())); } if source_path_exists && !force { diff --git a/src/commands/util.rs b/src/commands/util.rs index e142da33..aee2bd7d 100644 --- a/src/commands/util.rs +++ b/src/commands/util.rs @@ -159,7 +159,6 @@ pub fn mk_package_name_regex(regex: &str) -> Result { builder .build() .with_context(|| anyhow!("Failed to build regex from '{}'", regex)) - .map_err(Error::from) } /// Make a header column for the ascii_table crate @@ -259,7 +258,6 @@ pub fn get_date_filter( .checked_sub_signed(dur) .ok_or_else(|| anyhow!("Time calculation would overflow")) .with_context(|| anyhow!("Cannot subtract {} from 'now'", dur)) - .map_err(Error::from) }) .transpose() } diff --git a/src/config/util.rs b/src/config/util.rs index 99b1ba00..77922ed6 100644 --- a/src/config/util.rs +++ b/src/config/util.rs @@ -12,6 +12,9 @@ //! configuration and having to use default values. /// The default progress bar format +// Ignore a false positive Clippy warning (we pass this format string to +// `indicatif::ProgressBars` as `bar_template` instead of evaluating it here): +#[rustversion::attr(since(1.83), allow(clippy::literal_string_with_formatting_args))] pub fn default_progress_format() -> String { String::from("{elapsed_precise} {percent:>3}% {bar:5.cyan/blue} | {msg}") } diff --git a/src/db/models/githash.rs b/src/db/models/githash.rs index 8ea40093..5b1bbe0e 100644 --- a/src/db/models/githash.rs +++ b/src/db/models/githash.rs @@ -53,6 +53,5 @@ impl GitHash { .find(git_hash_id) .first::<_>(database_connection) .context("Loading GitHash") - .map_err(Error::from) } } diff --git a/src/db/models/job.rs b/src/db/models/job.rs index e311d17d..895d9573 100644 --- a/src/db/models/job.rs +++ b/src/db/models/job.rs @@ -92,7 +92,6 @@ impl Job { .filter(uuid.eq(job_uuid)) .first::(conn) .with_context(|| format!("Finding created job in database: {job_uuid}")) - .map_err(Error::from) }) } diff --git a/src/db/models/submit.rs b/src/db/models/submit.rs index ef885bf5..82c899d9 100644 --- a/src/db/models/submit.rs +++ b/src/db/models/submit.rs @@ -80,6 +80,5 @@ impl Submit { .filter(submits::uuid.eq(submit_id)) .first::(database_connection) .context("Loading submit") - .map_err(Error::from) } } diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index 1d91e904..4927450c 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -123,7 +123,6 @@ impl Endpoint { crate::config::EndpointType::Http => shiplift::Uri::from_str(ep.uri()) .map(shiplift::Docker::host) .with_context(|| anyhow!("Connecting to {}", ep.uri())) - .map_err(Error::from) .map(|docker| { Endpoint::builder() .name(ep_name.clone()) @@ -596,7 +595,6 @@ impl<'a> PreparedContainer<'a> { container.id() ) }) - .map_err(Error::from) }) .collect::>() .collect::>() @@ -608,7 +606,6 @@ impl<'a> PreparedContainer<'a> { ) }) .with_context(|| anyhow!("Copying sources to container {}", container.id())) - .map_err(Error::from) } async fn copy_patches_to_container(container: &Container<'_>, job: &RunnableJob) -> Result<()> { @@ -655,15 +652,12 @@ impl<'a> PreparedContainer<'a> { container.id() ) }) - .map_err(Error::from) }) .collect::>() .collect::>() .await - .map_err(Error::from) .inspect(|_| trace!("Copied all patches")) .with_context(|| anyhow!("Copying patches to container {}", container.id())) - .map_err(Error::from) } async fn copy_artifacts_to_container( @@ -746,8 +740,7 @@ impl<'a> PreparedContainer<'a> { container.id(), destination.display() ) - }) - .map_err(Error::from); + }); drop(art); // ensure `art` is moved into closure r }); @@ -767,7 +760,6 @@ impl<'a> PreparedContainer<'a> { ) }) .with_context(|| anyhow!("Copying artifacts to container {}", container.id())) - .map_err(Error::from) .map(|_| ()) } @@ -778,7 +770,6 @@ impl<'a> PreparedContainer<'a> { .await .inspect(|_| trace!("Successfully copied script to container {}", container.id())) .with_context(|| anyhow!("Copying the script into container {}", container.id())) - .map_err(Error::from) } pub async fn start(self) -> Result> { @@ -877,7 +868,6 @@ impl<'a> StartedContainer<'a> { .with_context(|| anyhow!("Sending log to log sink")) .map(|_| exited_successfully) }) - .map_err(Error::from) }) .collect::>>() .map(|r| { @@ -964,7 +954,6 @@ impl ExecutedContainer<'_> { self.create_info.id ) }) - .map_err(Error::from) }); let mut writelock = staging_store.write().await; diff --git a/src/endpoint/scheduler.rs b/src/endpoint/scheduler.rs index 74caaac4..11fc3b22 100644 --- a/src/endpoint/scheduler.rs +++ b/src/endpoint/scheduler.rs @@ -275,8 +275,7 @@ impl JobHandle { &endpoint_uri, &container_id, ) - }) - .map_err(Error::from); + }); if res.is_err() { trace!("Error was returned from script"); @@ -524,7 +523,6 @@ impl LogReceiver<'_> { .await .map(tokio::io::BufWriter::new) .with_context(|| anyhow!("Opening {}", path.display())) - .map_err(Error::from) }) } else { None diff --git a/src/filestore/path.rs b/src/filestore/path.rs index 44c5d183..866a4dfd 100644 --- a/src/filestore/path.rs +++ b/src/filestore/path.rs @@ -206,9 +206,7 @@ impl<'a> FullArtifactPath<'a> { pub async fn read(self) -> Result> { tokio::fs::read(self.joined()) .await - .map(Vec::from) .with_context(|| anyhow!("Reading artifact from path {}", self.0.display())) - .map_err(Error::from) } } diff --git a/src/filestore/staging.rs b/src/filestore/staging.rs index ac3ee8a8..006afb56 100644 --- a/src/filestore/staging.rs +++ b/src/filestore/staging.rs @@ -12,7 +12,6 @@ use std::fmt::Debug; use anyhow::anyhow; use anyhow::Context; -use anyhow::Error; use anyhow::Result; use futures::stream::Stream; use indicatif::ProgressBar; @@ -54,7 +53,6 @@ impl StagingStore { trace!("Unpacking archive to {}", dest.display()); dest.unpack_archive_here(tar::Archive::new(&bytes[..])) .context("Unpacking TAR") - .map_err(Error::from) }) .context("Concatenating the output bytestream")? .into_iter() diff --git a/src/package/script.rs b/src/package/script.rs index 9375275d..8a93daea 100644 --- a/src/package/script.rs +++ b/src/package/script.rs @@ -15,7 +15,6 @@ use std::process::ExitStatus; use anyhow::anyhow; use anyhow::Context as AnyhowContext; -use anyhow::Error; use anyhow::Result; use handlebars::{ Context, Handlebars, Helper, HelperDef, HelperResult, JsonRender, Output, PathAndJson, @@ -247,15 +246,13 @@ impl<'a> ScriptBuilder<'a> { trace!("Rendering Package: {:?}", package.debug_details()); } - hb.render("script", package) - .with_context(|| { - anyhow!( - "Rendering script for package {} {} failed", - package.name(), - package.version() - ) - }) - .map_err(Error::from) + hb.render("script", package).with_context(|| { + anyhow!( + "Rendering script for package {} {} failed", + package.name(), + package.version() + ) + }) } } diff --git a/src/package/version.rs b/src/package/version.rs index 6b9c6c86..fd9aca22 100644 --- a/src/package/version.rs +++ b/src/package/version.rs @@ -12,7 +12,6 @@ use std::ops::Deref; use anyhow::anyhow; use anyhow::Context; -use anyhow::Error; use anyhow::Result; use pom::parser::Parser as PomParser; use serde::Deserialize; @@ -67,7 +66,6 @@ impl TryFrom<&str> for PackageVersionConstraint { .parse(s.as_bytes()) .context(anyhow!("Failed to parse the following package version constraint: {}", s)) .context("A package version constraint must have a comparator (only `=` is currently supported) and a version string, like so: =0.1.0") - .map_err(Error::from) } } diff --git a/src/repository/fs/representation.rs b/src/repository/fs/representation.rs index 344fb371..7bf05f5d 100644 --- a/src/repository/fs/representation.rs +++ b/src/repository/fs/representation.rs @@ -266,7 +266,6 @@ fn load_file(path: &Path) -> Result { trace!("Reading {}", path.display()); std::fs::read_to_string(path) .with_context(|| anyhow!("Reading file from filesystem: {}", path.display())) - .map_err(Error::from) } #[cfg(test)] diff --git a/src/source/mod.rs b/src/source/mod.rs index 8e1fa830..b16d46af 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -12,7 +12,6 @@ use std::path::PathBuf; use anyhow::anyhow; use anyhow::Context; -use anyhow::Error; use anyhow::Result; use tracing::trace; use url::Url; @@ -140,6 +139,5 @@ impl SourceEntry { .open(&p) .await .with_context(|| anyhow!("Creating file: {}", p.display())) - .map_err(Error::from) } }