Skip to content

Commit e7638a7

Browse files
committed
better error messages: provide node names
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
1 parent 9c31476 commit e7638a7

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/cli.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,12 @@ fn prompt_deployment(
380380

381381
#[derive(Error, Debug)]
382382
pub enum RunDeployError {
383-
#[error("Failed to deploy profile: {0}")]
384-
DeployProfile(#[from] deploy::deploy::DeployProfileError),
385-
#[error("Failed to push profile: {0}")]
386-
PushProfile(#[from] deploy::push::PushProfileError),
383+
#[error("Failed to deploy profile to node {0}: {1}")]
384+
DeployProfile(String, deploy::deploy::DeployProfileError),
385+
#[error("Failed to build profile on node {0}: {0}")]
386+
BuildProfile(String, deploy::push::PushProfileError),
387+
#[error("Failed to push profile to node {0}: {0}")]
388+
PushProfile(String, deploy::push::PushProfileError),
387389
#[error("No profile named `{0}` was found")]
388390
ProfileNotFound(String),
389391
#[error("No node named `{0}` was found")]
@@ -396,10 +398,10 @@ pub enum RunDeployError {
396398
TomlFormat(#[from] toml::ser::Error),
397399
#[error("{0}")]
398400
PromptDeployment(#[from] PromptDeploymentError),
399-
#[error("Failed to revoke profile: {0}")]
400-
RevokeProfile(#[from] deploy::deploy::RevokeProfileError),
401-
#[error("Deployment failed, rolled back to previous generation")]
402-
Rollback
401+
#[error("Failed to revoke profile for node {0}: {1}")]
402+
RevokeProfile(String, deploy::deploy::RevokeProfileError),
403+
#[error("Deployment to node {0} failed, rolled back to previous generation")]
404+
Rollback(String)
403405
}
404406

405407
type ToDeploy<'a> = Vec<(
@@ -545,7 +547,7 @@ async fn run_deploy(
545547

546548
if deploy_data.merged_settings.interactive_sudo.unwrap_or(false) {
547549
warn!("Interactive sudo is enabled! Using a sudo password is less secure than correctly configured SSH keys.\nPlease use keys in production environments.");
548-
550+
549551
if deploy_data.merged_settings.sudo.is_some() {
550552
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.");
551553
} else {
@@ -586,11 +588,17 @@ async fn run_deploy(
586588
};
587589

588590
for data in data_iter() {
589-
deploy::push::build_profile(data).await?;
591+
let node_name: String = data.deploy_data.node_name.to_string();
592+
deploy::push::build_profile(data).await.map_err(|e| {
593+
RunDeployError::BuildProfile(node_name, e)
594+
})?;
590595
}
591596

592597
for data in data_iter() {
593-
deploy::push::push_profile(data).await?;
598+
let node_name: String = data.deploy_data.node_name.to_string();
599+
deploy::push::push_profile(data).await.map_err(|e| {
600+
RunDeployError::PushProfile(node_name, e)
601+
})?;
594602
}
595603

596604
let mut succeeded: Vec<(&deploy::DeployData, &deploy::DeployDefs)> = vec![];
@@ -613,12 +621,14 @@ async fn run_deploy(
613621
// the command line)
614622
for (deploy_data, deploy_defs) in &succeeded {
615623
if deploy_data.merged_settings.auto_rollback.unwrap_or(true) {
616-
deploy::deploy::revoke(*deploy_data, *deploy_defs).await?;
624+
deploy::deploy::revoke(*deploy_data, *deploy_defs).await.map_err(|e| {
625+
RunDeployError::RevokeProfile(deploy_data.node_name.to_string(), e)
626+
})?;
617627
}
618628
}
619-
return Err(RunDeployError::Rollback);
629+
return Err(RunDeployError::Rollback(deploy_data.node_name.to_string()));
620630
}
621-
return Err(RunDeployError::DeployProfile(e))
631+
return Err(RunDeployError::DeployProfile(deploy_data.node_name.to_string(), e))
622632
}
623633
succeeded.push((deploy_data, deploy_defs))
624634
}

0 commit comments

Comments
 (0)