Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.85.1"
components = ["clippy", "rustfmt"]
35 changes: 16 additions & 19 deletions src/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,21 @@ impl Launcher {
/// Tries to load the stored state from disk.
fn try_load_state(&self) -> Result<Option<State>> {
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.
Expand Down Expand Up @@ -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.");
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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),
)
Expand Down
20 changes: 10 additions & 10 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ pub(crate) fn versions_from_path<P: AsRef<Path>>(dir: P) -> Result<BTreeSet<Vers

/// Runs the given command as a child process.
pub(crate) fn run_node(mut command: Command) -> Result<NodeExitCode> {
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 => {
Expand All @@ -135,8 +135,8 @@ pub(crate) fn run_node(mut command: Command) -> Result<NodeExitCode> {
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");
}
}
}
Expand All @@ -149,7 +149,7 @@ pub(crate) fn map_and_log_error<T, E: std::error::Error + Send + Sync + 'static>
match result {
Ok(t) => Ok(t),
Err(error) => {
warn!(%error, "{}", error_msg);
warn!(%error, "{error_msg}");
Err(Error::new(error).context(error_msg))
}
}
Expand All @@ -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 {
Expand Down
Loading