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..3d10b2a --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.85.1" +components = ["clippy", "rustfmt"] \ No newline at end of file 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..b8d9018 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -111,20 +111,20 @@ 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( 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)) } } @@ -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 {