From 642b44176d5b9dc6159727fafaeab3f120769ef3 Mon Sep 17 00:00:00 2001 From: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:55:47 +0100 Subject: [PATCH] chore: catch and wrap deployment in progress when deleting the backend (#2366) --- .changeset/new-maps-lay.md | 5 +++++ packages/backend-deployer/src/cdk_error_mapper.test.ts | 7 +++++++ packages/backend-deployer/src/cdk_error_mapper.ts | 10 ++++++++++ 3 files changed, 22 insertions(+) create mode 100644 .changeset/new-maps-lay.md diff --git a/.changeset/new-maps-lay.md b/.changeset/new-maps-lay.md new file mode 100644 index 0000000000..e39a85c945 --- /dev/null +++ b/.changeset/new-maps-lay.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/backend-deployer': patch +--- + +catch and wrap deployment in progress when deleting the backend diff --git a/packages/backend-deployer/src/cdk_error_mapper.test.ts b/packages/backend-deployer/src/cdk_error_mapper.test.ts index 3b5611bf15..fbb5a33107 100644 --- a/packages/backend-deployer/src/cdk_error_mapper.test.ts +++ b/packages/backend-deployer/src/cdk_error_mapper.test.ts @@ -679,6 +679,13 @@ npm error enoent`, errorName: 'CloudformationResourceCircularDependencyError', expectedDownstreamErrorMessage: undefined, }, + { + errorMessage: `destroy failed Error: Stack [someStackArn] cannot be deleted while in status UPDATE_COMPLETE_CLEANUP_IN_PROGRESS`, + expectedTopLevelErrorMessage: + 'Backend failed to be deleted since the previous deployment is still in progress.', + errorName: 'DeleteFailedWhileDeploymentInProgressError', + expectedDownstreamErrorMessage: undefined, + }, ]; void describe('invokeCDKCommand', { concurrency: 1 }, () => { diff --git a/packages/backend-deployer/src/cdk_error_mapper.ts b/packages/backend-deployer/src/cdk_error_mapper.ts index bf1694e4ec..f191706926 100644 --- a/packages/backend-deployer/src/cdk_error_mapper.ts +++ b/packages/backend-deployer/src/cdk_error_mapper.ts @@ -471,6 +471,15 @@ export class CdkErrorMapper { errorName: 'CDKAssetPublishError', classification: 'ERROR', }, + { + // We capture the parameter name to show relevant error message + errorRegex: + /destroy failed Error: Stack \[(?.*)\] cannot be deleted while in status /, + humanReadableErrorMessage: `Backend failed to be deleted since the previous deployment is still in progress.`, + resolutionMessage: `Wait for the previous deployment for stack {stackArn} to be completed before attempting to delete again.`, + errorName: 'DeleteFailedWhileDeploymentInProgressError', + classification: 'ERROR', + }, // Generic error printed by CDK. Order matters so keep this towards the bottom of this list { // Error: .* is printed to stderr during cdk synth @@ -554,6 +563,7 @@ export type CDKDeploymentError = | 'CloudFormationDeletionError' | 'CloudFormationDeploymentError' | 'CommonNPMError' + | 'DeleteFailedWhileDeploymentInProgressError' | 'FilePermissionsError' | 'MissingDefineBackendError' | 'MultipleSandboxInstancesError'