From 3a70ce2141b820f871c1c3501834a584e9379ed1 Mon Sep 17 00:00:00 2001 From: Joe Sacher <321623+sacherjj@users.noreply.github.com> Date: Thu, 24 Jul 2025 08:42:56 -0400 Subject: [PATCH 1/5] Updating rust for clippy --- Cargo.lock | 2 +- rust-toolchain.toml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 rust-toolchain.toml diff --git a/Cargo.lock b/Cargo.lock index d1d2816..af435fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,7 +78,7 @@ checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" [[package]] name = "casper-node-launcher" -version = "1.0.6" +version = "1.0.7" dependencies = [ "anyhow", "backtrace", diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..00822fd --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.85.1" From f5952c4595354b0a454d2174974f48edba94e443 Mon Sep 17 00:00:00 2001 From: Joe Sacher <321623+sacherjj@users.noreply.github.com> Date: Thu, 24 Jul 2025 09:12:41 -0400 Subject: [PATCH 2/5] Pinning rust version to same as node --- rust-toolchain.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 00822fd..3d10b2a 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] channel = "1.85.1" +components = ["clippy", "rustfmt"] \ No newline at end of file From d9b4ebd084ef09dfc1777254026912d23101c043 Mon Sep 17 00:00:00 2001 From: Joe Sacher <321623+sacherjj@users.noreply.github.com> Date: Thu, 24 Jul 2025 10:55:55 -0400 Subject: [PATCH 3/5] Clippy updates. --- src/launcher.rs | 35 ++++++++++++++++------------------- src/main.rs | 8 ++++---- src/utils.rs | 14 +++++++------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/launcher.rs b/src/launcher.rs index 393235c..53ee1dc 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -200,24 +200,21 @@ impl Launcher { /// Tries to load the stored state from disk. fn try_load_state(&self) -> Result> { let state_path = self.state_path(); - state_path - .exists() - .then(|| { - debug!(path=%state_path.display(), "trying to read stored state"); - let contents = utils::map_and_log_error( - fs::read_to_string(&state_path), - format!("failed to read {}", state_path.display()), - )?; - - Ok(Some(utils::map_and_log_error( - toml::from_str(&contents), - format!("failed to parse {}", state_path.display()), - )?)) - }) - .unwrap_or_else(|| { - debug!(path=%state_path.display(), "stored state doesn't exist"); - Ok(None) - }) + if state_path.exists() { + debug!(path=%state_path.display(), "trying to read stored state"); + let contents = utils::map_and_log_error( + fs::read_to_string(&state_path), + format!("failed to read {}", state_path.display()), + )?; + + Ok(Some(utils::map_and_log_error( + toml::from_str(&contents), + format!("failed to parse {}", state_path.display()), + )?)) + } else { + debug!(path=%state_path.display(), "stored state doesn't exist"); + Ok(None) + } } /// Writes `self` to the hard-coded location as a TOML-encoded file. @@ -418,7 +415,7 @@ impl Launcher { info!("running shutdown script at {}.", SHUTDOWN_SCRIPT_PATH); let status = utils::map_and_log_error( Command::new(SHUTDOWN_SCRIPT_PATH).status(), - format!("couldn't execute script at {}", SHUTDOWN_SCRIPT_PATH), + format!("couldn't execute script at {SHUTDOWN_SCRIPT_PATH}"), )?; status.code().unwrap_or_else(|| { error!("shutdown script was terminated by a signal."); diff --git a/src/main.rs b/src/main.rs index 738cc22..8cde0f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,13 +42,13 @@ fn stop_child() { fn panic_hook(info: &PanicHookInfo) { let backtrace = Backtrace::new(); - eprintln!("{:?}", backtrace); + eprintln!("{backtrace:?}"); // Print panic info. if let Some(&string) = info.payload().downcast_ref::<&str>() { - eprintln!("node panicked: {}", string); + eprintln!("node panicked: {string}"); } else { - eprintln!("{}", info); + eprintln!("{info}"); } stop_child() @@ -80,7 +80,7 @@ fn main() -> Result<()> { .long("force-version") .value_name("version") .help("Forces the launcher to run the specified version of the node, for example \"1.2.3\"") - .validator(|arg: &str| Version::from_str(arg).map_err(|_| format!("unable to parse '{}' as version", arg))) + .validator(|arg: &str| Version::from_str(arg).map_err(|_| format!("unable to parse '{arg}' as version"))) .required(false) .takes_value(true), ) diff --git a/src/utils.rs b/src/utils.rs index 7c52cbe..98548a0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -116,15 +116,15 @@ pub(crate) fn run_node(mut command: Command) -> Result { let exit_status = map_and_log_error( child.wait(), - format!("failed to wait for completion of {:?}", command), + format!("failed to wait for completion of {command:?}"), )?; match exit_status.code() { Some(code) if code == NodeExitCode::Success as i32 => { - debug!("successfully finished running {:?}", command); + debug!("successfully finished running {command:?}"); Ok(NodeExitCode::Success) } Some(code) if code == NodeExitCode::ShouldDowngrade as i32 => { - debug!("finished running {:?} - should downgrade now", command); + debug!("finished running {command:?} - should downgrade now"); Ok(NodeExitCode::ShouldDowngrade) } Some(code) if code == NodeExitCode::ShouldExitLauncher as i32 => { @@ -135,8 +135,8 @@ pub(crate) fn run_node(mut command: Command) -> Result { Ok(NodeExitCode::ShouldExitLauncher) } _ => { - warn!(%exit_status, "failed running {:?}", command); - bail!("{:?} exited with error", command); + warn!(%exit_status, "failed running {command:?}"); + bail!("{command:?} exited with error"); } } } @@ -149,7 +149,7 @@ pub(crate) fn map_and_log_error match result { Ok(t) => Ok(t), Err(error) => { - warn!(%error, "{}", error_msg); + warn!(%error, "{error_msg}"); Err(Error::new(error).context(error_msg)) } } @@ -166,7 +166,7 @@ where // However, currently, it is only used to produce a proper debug message, // which is not sufficient justification to add a dependency to `itertools`. let result = iterable.into_iter().fold(String::new(), |result, item| { - format!("{}{}, ", result, item) + format!("{result}{item}, ") }); if result.is_empty() { result From 0aa638d146901f25b809bb168295616e28bbdd03 Mon Sep 17 00:00:00 2001 From: Joe Sacher <321623+sacherjj@users.noreply.github.com> Date: Thu, 24 Jul 2025 10:57:02 -0400 Subject: [PATCH 4/5] Fmt fix. --- src/utils.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 98548a0..daaa0a6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -165,9 +165,9 @@ where // This function should ideally be replaced with `itertools::join()`. // However, currently, it is only used to produce a proper debug message, // which is not sufficient justification to add a dependency to `itertools`. - let result = iterable.into_iter().fold(String::new(), |result, item| { - format!("{result}{item}, ") - }); + let result = iterable + .into_iter() + .fold(String::new(), |result, item| format!("{result}{item}, ")); if result.is_empty() { result } else { From 7ee83533e24dc886507097b179a81a1eccd2df1e Mon Sep 17 00:00:00 2001 From: Joe Sacher <321623+sacherjj@users.noreply.github.com> Date: Thu, 24 Jul 2025 10:59:56 -0400 Subject: [PATCH 5/5] Final clippy fix? --- src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index daaa0a6..b8d9018 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -111,7 +111,7 @@ pub(crate) fn versions_from_path>(dir: P) -> Result Result { - let mut child = map_and_log_error(command.spawn(), format!("failed to execute {:?}", command))?; + let mut child = map_and_log_error(command.spawn(), format!("failed to execute {command:?}"))?; crate::CHILD_PID.store(child.id(), Ordering::SeqCst); let exit_status = map_and_log_error(