From 6e3b6017b422ce01674cadc94ac43d2a24a93b5d Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Wed, 3 Jul 2024 15:15:01 -0400 Subject: [PATCH] Clippy & cleanup errors --- .../src/commands/network/container/start.rs | 25 +++++++++++-------- .../src/commands/network/container/stop.rs | 18 ++++++------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cmd/soroban-cli/src/commands/network/container/start.rs b/cmd/soroban-cli/src/commands/network/container/start.rs index db83a6e41b..c48cd7092d 100644 --- a/cmd/soroban-cli/src/commands/network/container/start.rs +++ b/cmd/soroban-cli/src/commands/network/container/start.rs @@ -19,10 +19,10 @@ const DOCKER_IMAGE: &str = "docker.io/stellar/quickstart"; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("⛔ ️Failed to connect to docker: {0}")] - ConnectionError(#[from] ConnectionError), + DockerConnectionFailed(#[from] ConnectionError), #[error("⛔ ️Failed to create container: {0}")] - BollardErr(#[from] bollard::errors::Error), + CreateContainerFailed(#[from] bollard::errors::Error), } #[derive(Debug, clap::Parser, Clone)] @@ -37,7 +37,7 @@ pub struct Cmd { #[arg(short = 'l', long)] pub limits: Option, - /// Argument to specify the HOST_PORT:CONTAINER_PORT mapping + /// Argument to specify the `HOST_PORT:CONTAINER_PORT` mapping #[arg(short = 'p', long, num_args = 1.., default_value = DEFAULT_PORT_MAPPING)] pub ports_mapping: Vec, @@ -118,11 +118,11 @@ fn print_log_message(cmd: &Cmd) { "ℹ️ To see the logs for this container run: stellar network container logs {arg} {additional_flags}", arg = cmd.container_args.container_name.as_ref().map_or_else( || cmd.network.to_string(), - |container_name| format!("--container-name {}", container_name) + |container_name| format!("--container-name {container_name}") ), additional_flags = cmd.container_args.docker_host.as_ref().map_or_else( - || String::new(), - |docker_host| format!("--docker-host {}", docker_host) + String::new, + |docker_host| format!("--docker-host {docker_host}") ) ); println!("{log_message}"); @@ -133,12 +133,15 @@ fn print_stop_message(cmd: &Cmd) { "ℹ️ To stop this container run: stellar network container stop {arg} {additional_flags}", arg = cmd.container_args.container_name.as_ref().map_or_else( || cmd.network.to_string(), - |container_name| format!("--container-name {}", container_name) + |container_name| format!("--container-name {container_name}") ), - additional_flags = cmd.container_args.docker_host.as_ref().map_or_else( - || String::new(), - |docker_host| format!("--docker-host {}", docker_host) - ) + additional_flags = cmd + .container_args + .docker_host + .as_ref() + .map_or_else(String::new, |docker_host| format!( + "--docker-host {docker_host}" + )) ); println!("{stop_message}"); } diff --git a/cmd/soroban-cli/src/commands/network/container/stop.rs b/cmd/soroban-cli/src/commands/network/container/stop.rs index 1b37cb5ede..8470865042 100644 --- a/cmd/soroban-cli/src/commands/network/container/stop.rs +++ b/cmd/soroban-cli/src/commands/network/container/stop.rs @@ -1,23 +1,23 @@ use crate::commands::network::container::shared::{ - connect_to_docker, get_container_name, Error as ConnectionError, Network, + connect_to_docker, get_container_name, Error as BollardConnectionError, Network, }; use super::shared::ContainerArgs; #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("Failed to stop container: {0}")] - StopConnectionContainerError(#[from] ConnectionError), + #[error("⛔ Failed to connect to docker: {0}")] + DockerConnectionFailed(#[from] BollardConnectionError), - #[error("Container {container_name} not found")] - ContainerNotFoundError { + #[error("⛔ Container {container_name} not found")] + ContainerNotFound { container_name: String, #[source] source: bollard::errors::Error, }, - #[error("Failed to stop container: {0}")] - StopContainerError(#[from] bollard::errors::Error), + #[error("⛔ Failed to stop container: {0}")] + ContainerStopFailed(#[from] bollard::errors::Error), } #[derive(Debug, clap::Parser, Clone)] @@ -42,12 +42,12 @@ impl Cmd { .map_err(|e| { let msg = e.to_string(); if msg.contains("No such container") { - Error::ContainerNotFoundError { + Error::ContainerNotFound { container_name: container_name.clone(), source: e, } } else { - Error::StopContainerError(e) + Error::ContainerStopFailed(e) } })?; println!("✅ Container stopped: {container_name}");