From 30f15e6e079e1e97afa56f27d0748aea068e3a76 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Fri, 3 Nov 2023 20:55:19 +0100 Subject: [PATCH 1/2] feat: suggest project restart when trying to delete --- cargo-shuttle/src/lib.rs | 20 +++++++++++++++++++- common/src/models/error.rs | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 10108d6d3..5130556b0 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -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::() { + // 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!(); + return err; + } + } + suggestions::project::project_request_failure( + err, + "Project delete failed", + true, + "deleting the project or getting project status fails repeatedly", + ) + })?; println!( "{}", diff --git a/common/src/models/error.rs b/common/src/models/error.rs index dc8969406..a64c72c8a 100644 --- a/common/src/models/error.rs +++ b/common/src/models/error.rs @@ -82,6 +82,7 @@ impl From 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 => { From a56c3f7205080292c4a36105384c75407e921376 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:15:39 +0100 Subject: [PATCH 2/2] feat: add docs link for more help --- cargo-shuttle/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 5130556b0..710f79054 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -1827,10 +1827,12 @@ impl Shuttle { 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",