Skip to content

Commit

Permalink
print status reason if some
Browse files Browse the repository at this point in the history
  • Loading branch information
Esgrove committed Oct 8, 2024
1 parent f6d56dc commit 878d6b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 7 additions & 3 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct CloudFormationStackData {
pub key_arn: Option<String>,
pub version: Option<u32>,
pub status: Option<StackStatus>,
pub status_reason: Option<String>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -161,13 +162,16 @@ impl fmt::Display for CloudFormationStackData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"bucket: {}\nkey ARN: {}\nversion: {}\nstatus: {}",
"status: {}\nbucket: {}\nkey ARN: {}\nversion: {}{}",
self.status
.as_ref()
.map_or("None".to_string(), std::string::ToString::to_string),
self.bucket_name.as_deref().unwrap_or("None"),
self.key_arn.as_deref().unwrap_or("None"),
self.version.map_or("None".to_string(), |v| v.to_string()),
self.status
self.status_reason
.as_ref()
.map_or("None".to_string(), std::string::ToString::to_string),
.map_or_else(String::new, |reason| format!("\nreason: {reason}"))
)
}
}
10 changes: 6 additions & 4 deletions rust/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,22 +438,23 @@ impl Vault {
stack_name: &str,
) -> Result<(), VaultError> {
let mut last_status: Option<StackStatus> = None;
let dots = [" ", ".", "..", "..."];
let clear_line = "\x1b[2K";
let dots = [".", "..", "...", ""];
loop {
match Self::get_cloudformation_stack_data(cf_client, stack_name).await {
Ok(stack_data) => {
if let Some(ref status) = stack_data.status {
// Check if stack has reached a terminal state
match status {
StackStatus::CreateComplete => {
println!("{stack_data}");
println!("{clear_line}{stack_data}");
println!("{}", "Stack creation completed successfully".green());
break;
}
StackStatus::CreateFailed
| StackStatus::RollbackFailed
| StackStatus::RollbackComplete => {
println!("{status}");
println!("{clear_line}{stack_data}");
return Err(VaultError::Error("Stack creation failed".to_string()));
}
_ => {
Expand All @@ -464,7 +465,7 @@ impl Vault {
}
// Continue waiting for stack creation to complete
for dot in &dots {
print!("\r{dot}");
print!("\r{clear_line}{dot}");
std::io::stdout().flush()?;
tokio::time::sleep(WAIT_ANIMATION_DURATION).await;
}
Expand Down Expand Up @@ -517,6 +518,7 @@ impl Vault {
if let Some(stacks) = stack_response.stacks {
if let Some(stack) = stacks.first() {
data.status.clone_from(&stack.stack_status);
data.status_reason.clone_from(&stack.stack_status_reason);
if let Some(outputs) = &stack.outputs {
for output in outputs {
if let Some(output_key) = output.output_key() {
Expand Down

0 comments on commit 878d6b5

Please sign in to comment.