Skip to content

Commit

Permalink
fix(cli): No exception when stack with wrong cases is deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Sep 23, 2023
1 parent ab52bb5 commit 56293ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,22 @@ export class CdkToolkit {
// The stacks will have been ordered for deployment, so reverse them for deletion.
stacks = stacks.reversed();

const artifacts = stacks.stackArtifacts;

if (!options.force) {
// eslint-disable-next-line max-len
const confirmed = await promptly.confirm(`Are you sure you want to delete: ${chalk.blue(stacks.stackArtifacts.map(s => s.hierarchicalId).join(', '))} (y/n)?`);
const confirmed = await promptly.confirm(`Are you sure you want to delete: ${chalk.blue(artifacts.map(s => s.hierarchicalId).join(', '))} (y/n)?`);
if (!confirmed) {
return;
}
}

if (artifacts.length === 0) {
throw new Error('Stack does not exist');
}

const action = options.fromDeploy ? 'deploy' : 'destroy';
for (const [index, stack] of stacks.stackArtifacts.entries()) {
for (const [index, stack] of artifacts.entries()) {
success('%s: destroying... [%s/%s]', chalk.blue(stack.displayName), index+1, stacks.stackCount);
try {
await this.props.deployments.destroyStack({
Expand Down
13 changes: 13 additions & 0 deletions packages/aws-cdk/test/cdk-toolkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,19 @@ describe('destroy', () => {
});
}).resolves;
});

test('fail on non-existent stack', async () => {
const toolkit = defaultToolkitSetup();

await expect(() => {
return toolkit.destroy({
selector: { patterns: ['Test-Stack-X'] },
exclusively: true,
force: true,
fromDeploy: true,
});
}).rejects.toThrowError('Stack does not exist');
});
});

describe('watch', () => {
Expand Down

0 comments on commit 56293ef

Please sign in to comment.