Skip to content

Commit cde4468

Browse files
authored
fix(cli): running --telemetry-file without the --unstable option creates a telemetry file (#731)
This feature is currently unstable, so it shouldn't apply at all if invoked without the `--unstable` flag. Right now, it creates a telemetry file with an event indicating the aforementioned failure. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent a6755f0 commit cde4468

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as path from 'path';
2+
import * as fs from 'fs-extra';
3+
import { integTest, withDefaultFixture } from '../../../lib';
4+
5+
jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime
6+
7+
integTest(
8+
'sending cli telemetry to file fails if not invoked with --unstable',
9+
withDefaultFixture(async (fixture) => {
10+
const telemetryFile = path.join(fixture.integTestDir, `telemetry-${Date.now()}.json`);
11+
try {
12+
await fixture.cdk(['list', `--telemetry-file=${telemetryFile}`]);
13+
throw new Error('Expected command to fail');
14+
} catch (error) {
15+
expect(fs.existsSync(telemetryFile)).toBeFalsy();
16+
expect(fixture.output.toString()).toContain('Unstable feature use');
17+
}
18+
}),
19+
);

packages/aws-cdk/lib/cli/cli.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
9999
caBundlePath: configuration.settings.get(['caBundlePath']),
100100
});
101101

102+
if (argv['telemetry-file'] && !configuration.settings.get(['unstable']).includes('telemetry')) {
103+
throw new ToolkitError('Unstable feature use: \'telemetry-file\' is unstable. It must be opted in via \'--unstable\', e.g. \'cdk deploy --unstable=telemetry --telemetry-file=my/file/path\'');
104+
}
105+
102106
try {
103107
await ioHost.startTelemetry(argv, configuration.context);
104108
} catch (e: any) {
@@ -209,10 +213,6 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
209213
throw new ToolkitError('You must either specify a list of Stacks or the `--all` argument');
210214
}
211215

212-
if (args['telemetry-file'] && !configuration.settings.get(['unstable']).includes('telemetry')) {
213-
throw new ToolkitError('Unstable feature use: \'telemetry-file\' is unstable. It must be opted in via \'--unstable\', e.g. \'cdk deploy --unstable=telemetry --telemetry-file=my/file/path\'');
214-
}
215-
216216
args.STACKS = args.STACKS ?? (args.STACK ? [args.STACK] : []);
217217
args.ENVIRONMENTS = args.ENVIRONMENTS ?? [];
218218

0 commit comments

Comments
 (0)