From 0936bde59ef2ea1deb5a4f1bcc478581fbd0e051 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 3 Jul 2019 10:17:11 +0200 Subject: [PATCH] fix(cli): stop processing on metadata errors (#3168) The new stack selection short circuiting broke stack error checking, which happened further down in that function. Move that functionality out as an explicit step to the CLI, as opposed to doing it implicitly as part of 'selectStacks'. NOTE: no test here, should be an integration test but the test will fail on the previous release so created a ticket for it. --- packages/aws-cdk/bin/cdk.ts | 2 ++ packages/aws-cdk/lib/api/cxapp/stacks.ts | 5 +---- packages/aws-cdk/lib/cdk-toolkit.ts | 2 ++ packages/aws-cdk/test/api/test.stacks.ts | 4 +++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index a12d380983bd4..45bc434c5ee49 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -281,6 +281,8 @@ async function initCommandLine() { defaultBehavior: DefaultSelection.AllStacks }); + appStacks.processMetadata(stacks); + // if we have a single stack, print it to STDOUT if (stacks.length === 1) { return stacks[0].template; diff --git a/packages/aws-cdk/lib/api/cxapp/stacks.ts b/packages/aws-cdk/lib/api/cxapp/stacks.ts index cbc12dfe1273b..a997b37a09cee 100644 --- a/packages/aws-cdk/lib/api/cxapp/stacks.ts +++ b/packages/aws-cdk/lib/api/cxapp/stacks.ts @@ -164,9 +164,6 @@ export class AppStacks { // Filter original array because it is in the right order const selectedList = stacks.filter(s => selectedStacks.has(s.name)); - // Only check selected stacks for errors - this.processMessages(selectedList); - return selectedList; } @@ -269,7 +266,7 @@ export class AppStacks { /** * Extracts 'aws:cdk:warning|info|error' metadata entries from the stack synthesis */ - private processMessages(stacks: cxapi.CloudFormationStackArtifact[]) { + public processMetadata(stacks: cxapi.CloudFormationStackArtifact[]) { let warnings = false; let errors = false; diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index b62617da4333d..1e59169736e82 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -81,6 +81,8 @@ export class CdkToolkit { defaultBehavior: DefaultSelection.OnlySingle }); + this.appStacks.processMetadata(stacks); + for (const stack of stacks) { if (stacks.length !== 1) { highlight(stack.name); } if (!stack.environment) { diff --git a/packages/aws-cdk/test/api/test.stacks.ts b/packages/aws-cdk/test/api/test.stacks.ts index c5d4b69763ec5..f90e1b368cb05 100644 --- a/packages/aws-cdk/test/api/test.stacks.ts +++ b/packages/aws-cdk/test/api/test.stacks.ts @@ -14,6 +14,7 @@ export = testCase({ const selected = await stacks.selectStacks(['withouterrors'], { defaultBehavior: DefaultSelection.AllStacks }); + stacks.processMetadata(selected); // THEN test.equal(selected[0].template.resource, 'noerrorresource'); @@ -27,9 +28,10 @@ export = testCase({ // WHEN try { - await stacks.selectStacks(['witherrors'], { + const selected = await stacks.selectStacks(['witherrors'], { defaultBehavior: DefaultSelection.AllStacks }); + stacks.processMetadata(selected); test.ok(false, 'Did not get exception'); } catch (e) {