From ca86bab9e9e8a0e60cec6793147abaec44a0ea8f Mon Sep 17 00:00:00 2001 From: notgne2 Date: Thu, 29 Oct 2020 19:33:53 -0700 Subject: Make all the errors work correctly (I am so so sorry) --- src/utils/deploy.rs | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'src/utils/deploy.rs') diff --git a/src/utils/deploy.rs b/src/utils/deploy.rs index 8ed7d8c..f395a3a 100644 --- a/src/utils/deploy.rs +++ b/src/utils/deploy.rs @@ -5,6 +5,8 @@ use std::borrow::Cow; use tokio::process::Command; +use thiserror::Error; + fn build_activate_command( activate_path_str: String, sudo: &Option, @@ -72,10 +74,26 @@ fn test_activation_command_builder() { ); } +#[derive(Error, Debug)] +pub enum DeployProfileError { + #[error("Failed to calculate activate bin path from deploy bin path: {0}")] + DeployPathToActivatePathError(#[from] super::DeployPathToActivatePathError), + #[error("Failed to run activation command over SSH: {0}")] + SSHActivateError(std::io::Error), + #[error("Activation over SSH resulted in a bad exit code: {0:?}")] + SSHActivateExitError(Option), + #[error("Failed to run confirmation command over SSH (the server should roll back): {0}")] + SSHConfirmError(std::io::Error), + #[error( + "Confirming activation over SSH resulted in a bad exit code (the server should roll back): {0:?}" + )] + SSHConfirmExitError(Option), +} + pub async fn deploy_profile( deploy_data: &super::DeployData<'_>, deploy_defs: &super::DeployDefs<'_>, -) -> Result<(), Box> { +) -> Result<(), DeployProfileError> { info!( "Activating profile `{}` for node `{}`", deploy_data.profile_name, deploy_data.node_name @@ -122,11 +140,16 @@ pub async fn deploy_profile( ssh_command = ssh_command.arg(ssh_opt); } - let ssh_exit_status = ssh_command.arg(self_activate_command).status().await?; + let ssh_exit_status = ssh_command + .arg(self_activate_command) + .status() + .await + .map_err(DeployProfileError::SSHActivateError)?; - if !ssh_exit_status.success() { - good_panic!("Activation over SSH failed"); - } + match ssh_exit_status.code() { + Some(0) => (), + a => return Err(DeployProfileError::SSHActivateExitError(a)), + }; info!("Success activating!"); @@ -153,14 +176,16 @@ pub async fn deploy_profile( confirm_command ); - let ssh_exit_status = ssh_confirm_command.arg(confirm_command).status().await?; + let ssh_exit_status = ssh_confirm_command + .arg(confirm_command) + .status() + .await + .map_err(DeployProfileError::SSHConfirmError)?; - if !ssh_exit_status.success() { - good_panic!( - "Failed to confirm deployment, the node will roll back in <{} seconds", - confirm_timeout - ); - } + match ssh_exit_status.code() { + Some(0) => (), + a => return Err(DeployProfileError::SSHConfirmExitError(a)), + }; info!("Deployment confirmed."); } -- cgit v1.2.3