Skip to content

Commit

Permalink
better error messages: provide node names
Browse files Browse the repository at this point in the history
printing what node caused an error is very useful for debugging
build or deployment failures, especially when deploying to several
nodes at the same time
  • Loading branch information
PhilTaken committed Jun 10, 2024
1 parent 9c31476 commit e7638a7
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,12 @@ fn prompt_deployment(

#[derive(Error, Debug)]
pub enum RunDeployError {
#[error("Failed to deploy profile: {0}")]
DeployProfile(#[from] deploy::deploy::DeployProfileError),
#[error("Failed to push profile: {0}")]
PushProfile(#[from] deploy::push::PushProfileError),
#[error("Failed to deploy profile to node {0}: {1}")]
DeployProfile(String, deploy::deploy::DeployProfileError),
#[error("Failed to build profile on node {0}: {0}")]
BuildProfile(String, deploy::push::PushProfileError),
#[error("Failed to push profile to node {0}: {0}")]
PushProfile(String, deploy::push::PushProfileError),
#[error("No profile named `{0}` was found")]
ProfileNotFound(String),
#[error("No node named `{0}` was found")]
Expand All @@ -396,10 +398,10 @@ pub enum RunDeployError {
TomlFormat(#[from] toml::ser::Error),
#[error("{0}")]
PromptDeployment(#[from] PromptDeploymentError),
#[error("Failed to revoke profile: {0}")]
RevokeProfile(#[from] deploy::deploy::RevokeProfileError),
#[error("Deployment failed, rolled back to previous generation")]
Rollback
#[error("Failed to revoke profile for node {0}: {1}")]
RevokeProfile(String, deploy::deploy::RevokeProfileError),
#[error("Deployment to node {0} failed, rolled back to previous generation")]
Rollback(String)
}

type ToDeploy<'a> = Vec<(
Expand Down Expand Up @@ -545,7 +547,7 @@ async fn run_deploy(

if deploy_data.merged_settings.interactive_sudo.unwrap_or(false) {
warn!("Interactive sudo is enabled! Using a sudo password is less secure than correctly configured SSH keys.\nPlease use keys in production environments.");

if deploy_data.merged_settings.sudo.is_some() {
warn!("Custom sudo commands should be configured to accept password input from stdin when using the 'interactive sudo' option. Deployment may fail if the custom command ignores stdin.");
} else {
Expand Down Expand Up @@ -586,11 +588,17 @@ async fn run_deploy(
};

for data in data_iter() {
deploy::push::build_profile(data).await?;
let node_name: String = data.deploy_data.node_name.to_string();
deploy::push::build_profile(data).await.map_err(|e| {
RunDeployError::BuildProfile(node_name, e)
})?;
}

for data in data_iter() {
deploy::push::push_profile(data).await?;
let node_name: String = data.deploy_data.node_name.to_string();
deploy::push::push_profile(data).await.map_err(|e| {
RunDeployError::PushProfile(node_name, e)
})?;
}

let mut succeeded: Vec<(&deploy::DeployData, &deploy::DeployDefs)> = vec![];
Expand All @@ -613,12 +621,14 @@ async fn run_deploy(
// the command line)
for (deploy_data, deploy_defs) in &succeeded {
if deploy_data.merged_settings.auto_rollback.unwrap_or(true) {
deploy::deploy::revoke(*deploy_data, *deploy_defs).await?;
deploy::deploy::revoke(*deploy_data, *deploy_defs).await.map_err(|e| {
RunDeployError::RevokeProfile(deploy_data.node_name.to_string(), e)
})?;
}
}
return Err(RunDeployError::Rollback);
return Err(RunDeployError::Rollback(deploy_data.node_name.to_string()));
}
return Err(RunDeployError::DeployProfile(e))
return Err(RunDeployError::DeployProfile(deploy_data.node_name.to_string(), e))
}
succeeded.push((deploy_data, deploy_defs))
}
Expand Down

0 comments on commit e7638a7

Please sign in to comment.