Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suggest project restart when trying to delete #1366

Merged
merged 2 commits into from Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion cargo-shuttle/src/lib.rs
Expand Up @@ -1819,7 +1819,25 @@ 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") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should use plain string match or have a constant somewhere for the message and check that.

e.g.

const PROJECT_NOT_READY_MSG: &str =  "project not ready. Try running `cargo shuttle project restart`.";

It is something trivial but worth considering I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used a small string for matching, because if an entire string is used like that, a single change to the string will be breaking, like we saw in #1360. In this scenario, it wouldn't break functionality, just the extra hint, but still.

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!();
return err;
}
}
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