Skip to content

Commit

Permalink
fix(cli): stop processing on metadata errors (#3168)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rix0rrr authored and Elad Ben-Israel committed Jul 3, 2019
1 parent b2761e9 commit 0936bde
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions packages/aws-cdk/lib/api/cxapp/stacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion packages/aws-cdk/test/api/test.stacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) {
Expand Down

0 comments on commit 0936bde

Please sign in to comment.