Skip to content

Commit fdf54d0

Browse files
kaizenccmrgrain
andauthored
docs(toolkit-lib): CODE_REGISTRY.md tracks valid codes and their documentation (#44)
closes aws/aws-cdk#33434 generates `CODE_REGISTRY.md` using information gathered in `codes.ts`. this pr: - updates `codes.ts` to have additional information stored - introduces a script that generates a markdown table from the `CODES` object - updates projen to build `CODE_REGISTRY.md` as a post-build step --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Co-authored-by: Momo Kornher <[email protected]>
1 parent 757ae69 commit fdf54d0

File tree

13 files changed

+385
-94
lines changed

13 files changed

+385
-94
lines changed

.projenrc.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ toolkitLib.package.addField('exports', {
11741174
'./package.json': './package.json',
11751175
});
11761176

1177+
toolkitLib.postCompileTask.exec('ts-node scripts/gen-code-registry.ts');
11771178
toolkitLib.postCompileTask.exec('node build-tools/bundle.mjs');
11781179
// Smoke test built JS files
11791180
toolkitLib.postCompileTask.exec('node ./lib/index.js >/dev/null 2>/dev/null </dev/null');

packages/@aws-cdk/toolkit-lib/.projen/tasks.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Toolkit Code Registry
2+
3+
| Code | Description | Level | Data Interface |
4+
|------|-------------|-------|----------------|
5+
| CDK_TOOLKIT_I1000 | Provides synthesis times. | info | n/a |
6+
| CDK_TOOLKIT_I1901 | Provides stack data | result | [StackData](docs/interfaces/StackData.html) |
7+
| CDK_TOOLKIT_I1902 | Successfully deployed stacks | result | [AssemblyData](docs/interfaces/AssemblyData.html) |
8+
| CDK_TOOLKIT_I2901 | Provides details on the selected stacks and their dependencies | result | n/a |
9+
| CDK_TOOLKIT_E3900 | Resource import failed | error | n/a |
10+
| CDK_TOOLKIT_I5000 | Provides deployment times | info | n/a |
11+
| CDK_TOOLKIT_I5001 | Provides total time in deploy action, including synth and rollback | info | [Duration](docs/interfaces/Duration.html) |
12+
| CDK_TOOLKIT_I5002 | Provides time for resource migration | info | n/a |
13+
| CDK_TOOLKIT_I5031 | Informs about any log groups that are traced as part of the deployment | info | n/a |
14+
| CDK_TOOLKIT_I5050 | Confirm rollback during deployment | info | n/a |
15+
| CDK_TOOLKIT_I5060 | Confirm deploy security sensitive changes | info | n/a |
16+
| CDK_TOOLKIT_I5900 | Deployment results on success | result | [SuccessfulDeployStackResult](docs/interfaces/SuccessfulDeployStackResult.html) |
17+
| CDK_TOOLKIT_E5001 | No stacks found | error | n/a |
18+
| CDK_TOOLKIT_I6000 | Provides rollback times | info | n/a |
19+
| CDK_TOOLKIT_E6001 | No stacks found | error | n/a |
20+
| CDK_TOOLKIT_E6900 | Rollback failed | error | n/a |
21+
| CDK_TOOLKIT_I7000 | Provides destroy times | info | n/a |
22+
| CDK_TOOLKIT_I7010 | Confirm destroy stacks | info | n/a |
23+
| CDK_TOOLKIT_E7010 | Action was aborted due to negative confirmation of request | error | n/a |
24+
| CDK_TOOLKIT_E7900 | Stack deletion failed | error | n/a |
25+
| CDK_ASSEMBLY_I0042 | Writing updated context | debug | n/a |
26+
| CDK_ASSEMBLY_I0241 | Fetching missing context | debug | n/a |
27+
| CDK_ASSEMBLY_I1000 | Cloud assembly output starts | debug | n/a |
28+
| CDK_ASSEMBLY_I1001 | Output lines emitted by the cloud assembly to stdout | info | n/a |
29+
| CDK_ASSEMBLY_E1002 | Output lines emitted by the cloud assembly to stderr | error | n/a |
30+
| CDK_ASSEMBLY_I1003 | Cloud assembly output finished | info | n/a |
31+
| CDK_ASSEMBLY_E1111 | Incompatible CDK CLI version. Upgrade needed. | error | n/a |

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/context-aware-source.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as cxapi from '@aws-cdk/cx-api';
33
import { ToolkitServices } from '../../../toolkit/private';
44
import { type Context, contextproviders, PROJECT_CONTEXT } from '../../aws-cdk';
55
import { ToolkitError } from '../../errors';
6-
import { ActionAwareIoHost, debug } from '../../io/private';
6+
import { ActionAwareIoHost, CODES, debug } from '../../io/private';
77
import { ICloudAssemblySource } from '../types';
88

99
export interface ContextAwareCloudAssemblyProps {
@@ -82,7 +82,7 @@ export class ContextAwareCloudAssembly implements ICloudAssemblySource {
8282
previouslyMissingKeys = missingKeys;
8383

8484
if (tryLookup) {
85-
await this.ioHost.notify(debug('Some context information is missing. Fetching...', 'CDK_ASSEMBLY_I0241', {
85+
await this.ioHost.notify(debug('Some context information is missing. Fetching...', CODES.CDK_ASSEMBLY_I0241, {
8686
missingKeys: Array.from(missingKeys),
8787
}));
8888
await contextproviders.provideContextValues(
@@ -92,7 +92,7 @@ export class ContextAwareCloudAssembly implements ICloudAssemblySource {
9292
);
9393

9494
// Cache the new context to disk
95-
await this.ioHost.notify(debug(`Writing updated context to ${this.contextFile}...`, 'CDK_ASSEMBLY_I0042', {
95+
await this.ioHost.notify(debug(`Writing updated context to ${this.contextFile}...`, CODES.CDK_ASSEMBLY_I0042, {
9696
contextFile: this.contextFile,
9797
context: this.context.all,
9898
}));

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { lte } from 'semver';
77
import { prepareDefaultEnvironment as oldPrepare, prepareContext, spaceAvailableForContext, Settings, loadTree, some, splitBySize, versionNumber } from '../../../api/aws-cdk';
88
import { ToolkitServices } from '../../../toolkit/private';
99
import { ToolkitError } from '../../errors';
10-
import { ActionAwareIoHost, asLogger, error } from '../../io/private';
10+
import { ActionAwareIoHost, asLogger, CODES, error } from '../../io/private';
1111
import type { AppSynthOptions } from '../source-builder';
1212

1313
export { guessExecutable } from '../../../api/aws-cdk';
@@ -160,7 +160,7 @@ export async function assemblyFromDirectory(assemblyDir: string, ioHost: ActionA
160160
// this means the CLI version is too old.
161161
// we instruct the user to upgrade.
162162
const message = 'This AWS CDK Toolkit is not compatible with the AWS CDK library used by your application. Please upgrade to the latest version.';
163-
await ioHost.notify(error(message, 'CDK_ASSEMBLY_E1111', { error: err.message }));
163+
await ioHost.notify(error(message, CODES.CDK_ASSEMBLY_E1111, { error: err.message }));
164164
throw new ToolkitError(`${message}\n(${err.message}`);
165165
}
166166
throw err;

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/source-builder.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as cxapi from '@aws-cdk/cx-api';
22
import * as fs from 'fs-extra';
3-
import type { ICloudAssemblySource } from '../';
3+
import type { AssemblySourceProps, ICloudAssemblySource } from '../';
44
import { ContextAwareCloudAssembly, ContextAwareCloudAssemblyProps } from './context-aware-source';
55
import { execInChildProcess } from './exec';
66
import { assemblyFromDirectory, changeDir, determineOutputDirectory, guessExecutable, prepareDefaultEnvironment, withContext, withEnv } from './prepare-source';
77
import { ToolkitServices } from '../../../toolkit/private';
88
import { Context, ILock, RWLock, Settings } from '../../aws-cdk';
99
import { ToolkitError } from '../../errors';
10-
import { debug, error, info } from '../../io/private';
11-
import { AssemblyBuilder, AssemblySourceProps } from '../source-builder';
10+
import { CODES, debug, error, info } from '../../io/private';
11+
import { AssemblyBuilder } from '../source-builder';
1212

1313
export abstract class CloudAssemblySourceBuilder {
1414
/**
@@ -126,10 +126,10 @@ export abstract class CloudAssemblySourceBuilder {
126126
eventPublisher: async (type, line) => {
127127
switch (type) {
128128
case 'data_stdout':
129-
await services.ioHost.notify(info(line, 'CDK_ASSEMBLY_I1001'));
129+
await services.ioHost.notify(info(line, CODES.CDK_ASSEMBLY_I1001));
130130
break;
131131
case 'data_stderr':
132-
await services.ioHost.notify(error(line, 'CDK_ASSEMBLY_E1002'));
132+
await services.ioHost.notify(error(line, CODES.CDK_ASSEMBLY_E1002));
133133
break;
134134
}
135135
},

packages/@aws-cdk/toolkit-lib/lib/api/io/private/codes.ts

+175-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
1-
import { IoMessageCode } from '../io-message';
1+
import { IoMessageCode, IoMessageLevel } from '../io-message';
2+
3+
/**
4+
* Information for each IO Message Code.
5+
*/
6+
export interface CodeInfo {
7+
/**
8+
* The message code.
9+
*/
10+
code: IoMessageCode;
11+
12+
/**
13+
* A brief description of the meaning of this IO Message.
14+
*/
15+
description: string;
16+
17+
/**
18+
* The message level
19+
*/
20+
level: IoMessageLevel;
21+
22+
/**
23+
* The name of the payload interface, if applicable.
24+
* Some Io Messages include a payload, with a specific interface. The name of
25+
* the interface is specified here so that it can be linked with the message
26+
* when documentation is generated.
27+
*
28+
* The interface _must_ be exposed directly from toolkit-lib, so that it will
29+
* have a documentation page generated (that can be linked to).
30+
*/
31+
interface?: string;
32+
}
33+
34+
function codeInfo(info: CodeInfo): CodeInfo {
35+
return info;
36+
}
237

338
/**
439
* We have a rough system by which we assign message codes:
@@ -8,55 +43,162 @@ import { IoMessageCode } from '../io-message';
843
*/
944
export const CODES = {
1045
// 1: Synth
11-
CDK_TOOLKIT_I1000: 'Provides synthesis times',
12-
CDK_TOOLKIT_I1901: 'Provides stack data',
13-
CDK_TOOLKIT_I1902: 'Successfully deployed stacks',
46+
CDK_TOOLKIT_I1000: codeInfo({
47+
code: 'CDK_TOOLKIT_I1000',
48+
description: 'Provides synthesis times.',
49+
level: 'info',
50+
}),
51+
CDK_TOOLKIT_I1901: codeInfo({
52+
code: 'CDK_TOOLKIT_I1901',
53+
description: 'Provides stack data',
54+
level: 'result',
55+
interface: 'StackData',
56+
}),
57+
CDK_TOOLKIT_I1902: codeInfo({
58+
code: 'CDK_TOOLKIT_I1902',
59+
description: 'Successfully deployed stacks',
60+
level: 'result',
61+
interface: 'AssemblyData',
62+
}),
1463

1564
// 2: List
16-
CDK_TOOLKIT_I2901: 'Provides details on the selected stacks and their dependencies',
65+
CDK_TOOLKIT_I2901: codeInfo({
66+
code: 'CDK_TOOLKIT_I2901',
67+
description: 'Provides details on the selected stacks and their dependencies',
68+
level: 'result',
69+
}),
1770

1871
// 3: Import & Migrate
19-
CDK_TOOLKIT_E3900: 'Resource import failed',
72+
CDK_TOOLKIT_E3900: codeInfo({
73+
code: 'CDK_TOOLKIT_E3900',
74+
description: 'Resource import failed',
75+
level: 'error',
76+
}),
2077

2178
// 4: Diff
2279

2380
// 5: Deploy & Watch
24-
CDK_TOOLKIT_I5000: 'Provides deployment times',
25-
CDK_TOOLKIT_I5001: 'Provides total time in deploy action, including synth and rollback',
26-
CDK_TOOLKIT_I5002: 'Provides time for resource migration',
27-
CDK_TOOLKIT_I5031: 'Informs about any log groups that are traced as part of the deployment',
28-
CDK_TOOLKIT_I5050: 'Confirm rollback during deployment',
29-
CDK_TOOLKIT_I5060: 'Confirm deploy security sensitive changes',
30-
CDK_TOOLKIT_I5900: 'Deployment results on success',
81+
CDK_TOOLKIT_I5000: codeInfo({
82+
code: 'CDK_TOOLKIT_I5000',
83+
description: 'Provides deployment times',
84+
level: 'info',
85+
}),
86+
CDK_TOOLKIT_I5001: codeInfo({
87+
code: 'CDK_TOOLKIT_I5001',
88+
description: 'Provides total time in deploy action, including synth and rollback',
89+
level: 'info',
90+
interface: 'Duration',
91+
}),
92+
CDK_TOOLKIT_I5002: codeInfo({
93+
code: 'CDK_TOOLKIT_I5002',
94+
description: 'Provides time for resource migration',
95+
level: 'info',
96+
}),
97+
CDK_TOOLKIT_I5031: codeInfo({
98+
code: 'CDK_TOOLKIT_I5031',
99+
description: 'Informs about any log groups that are traced as part of the deployment',
100+
level: 'info',
101+
}),
102+
CDK_TOOLKIT_I5050: codeInfo({
103+
code: 'CDK_TOOLKIT_I5050',
104+
description: 'Confirm rollback during deployment',
105+
level: 'info',
106+
}),
107+
CDK_TOOLKIT_I5060: codeInfo({
108+
code: 'CDK_TOOLKIT_I5060',
109+
description: 'Confirm deploy security sensitive changes',
110+
level: 'info',
111+
}),
112+
CDK_TOOLKIT_I5900: codeInfo({
113+
code: 'CDK_TOOLKIT_I5900',
114+
description: 'Deployment results on success',
115+
level: 'result',
116+
interface: 'SuccessfulDeployStackResult',
117+
}),
31118

32-
CDK_TOOLKIT_E5001: 'No stacks found',
119+
CDK_TOOLKIT_E5001: codeInfo({
120+
code: 'CDK_TOOLKIT_E5001',
121+
description: 'No stacks found',
122+
level: 'error',
123+
}),
33124

34125
// 6: Rollback
35-
CDK_TOOLKIT_I6000: 'Provides rollback times',
126+
CDK_TOOLKIT_I6000: codeInfo({
127+
code: 'CDK_TOOLKIT_I6000',
128+
description: 'Provides rollback times',
129+
level: 'info',
130+
}),
36131

37-
CDK_TOOLKIT_E6001: 'No stacks found',
38-
CDK_TOOLKIT_E6900: 'Rollback failed',
132+
CDK_TOOLKIT_E6001: codeInfo({
133+
code: 'CDK_TOOLKIT_E6001',
134+
description: 'No stacks found',
135+
level: 'error',
136+
}),
137+
CDK_TOOLKIT_E6900: codeInfo({
138+
code: 'CDK_TOOLKIT_E6900',
139+
description: 'Rollback failed',
140+
level: 'error',
141+
}),
39142

40143
// 7: Destroy
41-
CDK_TOOLKIT_I7000: 'Provides destroy times',
42-
CDK_TOOLKIT_I7010: 'Confirm destroy stacks',
144+
CDK_TOOLKIT_I7000: codeInfo({
145+
code: 'CDK_TOOLKIT_I7000',
146+
description: 'Provides destroy times',
147+
level: 'info',
148+
}),
149+
CDK_TOOLKIT_I7010: codeInfo({
150+
code: 'CDK_TOOLKIT_I7010',
151+
description: 'Confirm destroy stacks',
152+
level: 'info',
153+
}),
43154

44-
CDK_TOOLKIT_E7010: 'Action was aborted due to negative confirmation of request',
45-
CDK_TOOLKIT_E7900: 'Stack deletion failed',
155+
CDK_TOOLKIT_E7010: codeInfo({
156+
code: 'CDK_TOOLKIT_E7010',
157+
description: 'Action was aborted due to negative confirmation of request',
158+
level: 'error',
159+
}),
160+
CDK_TOOLKIT_E7900: codeInfo({
161+
code: 'CDK_TOOLKIT_E7900',
162+
description: 'Stack deletion failed',
163+
level: 'error',
164+
}),
46165

47166
// 9: Bootstrap
48167

49168
// Assembly codes
50-
CDK_ASSEMBLY_I0042: 'Writing updated context',
51-
CDK_ASSEMBLY_I0241: 'Fetching missing context',
52-
CDK_ASSEMBLY_I1000: 'Cloud assembly output starts',
53-
CDK_ASSEMBLY_I1001: 'Output lines emitted by the cloud assembly to stdout',
54-
CDK_ASSEMBLY_E1002: 'Output lines emitted by the cloud assembly to stderr',
55-
CDK_ASSEMBLY_I1003: 'Cloud assembly output finished',
56-
CDK_ASSEMBLY_E1111: 'Incompatible CDK CLI version. Upgrade needed.',
169+
CDK_ASSEMBLY_I0042: codeInfo({
170+
code: 'CDK_ASSEMBLY_I0042',
171+
description: 'Writing updated context',
172+
level: 'debug',
173+
}),
174+
CDK_ASSEMBLY_I0241: codeInfo({
175+
code: 'CDK_ASSEMBLY_I0241',
176+
description: 'Fetching missing context',
177+
level: 'debug',
178+
}),
179+
CDK_ASSEMBLY_I1000: codeInfo({
180+
code: 'CDK_ASSEMBLY_I1000',
181+
description: 'Cloud assembly output starts',
182+
level: 'debug',
183+
}),
184+
CDK_ASSEMBLY_I1001: codeInfo({
185+
code: 'CDK_ASSEMBLY_I1001',
186+
description: 'Output lines emitted by the cloud assembly to stdout',
187+
level: 'info',
188+
}),
189+
CDK_ASSEMBLY_E1002: codeInfo({
190+
code: 'CDK_ASSEMBLY_E1002',
191+
description: 'Output lines emitted by the cloud assembly to stderr',
192+
level: 'error',
193+
}),
194+
CDK_ASSEMBLY_I1003: codeInfo({
195+
code: 'CDK_ASSEMBLY_I1003',
196+
description: 'Cloud assembly output finished',
197+
level: 'info',
198+
}),
199+
CDK_ASSEMBLY_E1111: codeInfo({
200+
code: 'CDK_ASSEMBLY_E1111',
201+
description: 'Incompatible CDK CLI version. Upgrade needed.',
202+
level: 'error',
203+
}),
57204
};
58-
59-
// If we give CODES a type with key: IoMessageCode,
60-
// this dynamically generated type will generalize to allow all IoMessageCodes.
61-
// Instead, we will validate that VALID_CODE must be IoMessageCode with the '&'.
62-
export type VALID_CODE = keyof typeof CODES & IoMessageCode;

0 commit comments

Comments
 (0)