Skip to content

Commit 98a1bfa

Browse files
authored
fix(cli): when CDK library is too old, an empty flags table is displayed (#797)
Returns an error message for users if they run the `cdk flags` command with an incompatible version of `aws-cdk-lib`. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent add2ae7 commit 98a1bfa

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/aws-cdk/lib/commands/flag-operations.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ interface FlagOperationsParams {
4444

4545
export async function handleFlags(flagData: FeatureFlag[], ioHelper: IoHelper, options: FlagsOptions, toolkit: Toolkit) {
4646
flagData = flagData.filter(flag => !OBSOLETE_FLAGS.includes(flag.name));
47+
48+
if (flagData.length == 0) {
49+
await ioHelper.defaults.error('The \'cdk flags\' command is not compatible with the AWS CDK library used by your application. Please upgrade to 2.212.0 or above.');
50+
return;
51+
}
52+
4753
let params = {
4854
flagData,
4955
toolkit,

packages/aws-cdk/test/commands/flag-operations.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,17 @@ describe('handleFlags', () => {
457457
await cleanupCdkJsonFile(cdkJsonPath);
458458
requestResponseSpy.mockRestore();
459459
});
460+
461+
test('displays notice when user is on incompatible version', async () => {
462+
const mockNoFlagsData: FeatureFlag[] = [];
463+
464+
const options: FlagsOptions = {};
465+
466+
await handleFlags(mockNoFlagsData, ioHelper, options, mockToolkit);
467+
468+
const plainTextOutput = output();
469+
expect(plainTextOutput).toContain('The \'cdk flags\' command is not compatible with the AWS CDK library used by your application. Please upgrade to 2.212.0 or above.');
470+
});
460471
});
461472

462473
describe('modifyValues', () => {

0 commit comments

Comments
 (0)