Skip to content

Commit

Permalink
feat: suggest project restart when trying to delete (#1366)
Browse files Browse the repository at this point in the history
* feat: suggest project restart when trying to delete

* feat: add docs link for more help
  • Loading branch information
jonaro00 committed Nov 8, 2023
1 parent 1c003cd commit 3f14217
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cargo-shuttle/src/lib.rs
Expand Up @@ -1819,7 +1819,27 @@ impl Shuttle {
let client = self.client.as_ref().unwrap();

// If a check fails, print the returned error
client.delete_project(self.ctx.project_name(), true).await?;
client.delete_project(self.ctx.project_name(), true).await.map_err(|err| {
if let Some(api_error) = err.downcast_ref::<ApiError>() {
// If the returned error string changes, this could break
if api_error.message.contains("not ready") {
println!("{}", "Project delete failed".red());
println!();
println!("{}", "Try restarting the project with `cargo shuttle project restart` first.".yellow());
println!("{}", "This is needed to check for any resources linked to it.".yellow());
println!("{}", "For more help with deleting projects, visit https://docs.shuttle.rs/support/delete-project".yellow());
println!();
return err;
}
}
println!("{}", "For more help with deleting projects, visit https://docs.shuttle.rs/support/delete-project".yellow());
suggestions::project::project_request_failure(
err,
"Project delete failed",
true,
"deleting the project or getting project status fails repeatedly",
)
})?;

println!(
"{}",
Expand Down
1 change: 1 addition & 0 deletions common/src/models/error.rs
Expand Up @@ -82,6 +82,7 @@ impl From<ErrorKind> for ApiError {
),
ErrorKind::ProjectNotReady => (
StatusCode::SERVICE_UNAVAILABLE,
// "not ready" is matched against in cargo-shuttle for giving further instructions on project deletion
"project not ready. Try running `cargo shuttle project restart`.",
),
ErrorKind::ProjectUnavailable => {
Expand Down

0 comments on commit 3f14217

Please sign in to comment.