Skip to content

Commit 889bdb7

Browse files
authored
Handle case where synthesis renders empty cdk assembly (#2192)
* Handle case where synthesis renders empty cdk assembly * fix test * undo that * actual fix
1 parent 7bf0c64 commit 889bdb7

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

.changeset/early-pens-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/backend-deployer': patch
3+
---
4+
5+
Handle case where synthesis renders empty cdk assembly

packages/backend-deployer/src/cdk_error_mapper.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,20 @@ const testErrorMappings = [
346346
errorName: 'CloudFormationDeploymentError',
347347
expectedDownstreamErrorMessage: undefined,
348348
},
349+
{
350+
errorMessage: `ENOENT: no such file or directory, open '.amplify/artifacts/cdk.out/manifest.json'`,
351+
expectedTopLevelErrorMessage:
352+
'The Amplify backend definition is missing `defineBackend` call.',
353+
errorName: 'MissingDefineBackendError',
354+
expectedDownstreamErrorMessage: undefined,
355+
},
356+
{
357+
errorMessage: `ENOENT: no such file or directory, open '.amplify\\artifacts\\cdk.out\\manifest.json'`,
358+
expectedTopLevelErrorMessage:
359+
'The Amplify backend definition is missing `defineBackend` call.',
360+
errorName: 'MissingDefineBackendError',
361+
expectedDownstreamErrorMessage: undefined,
362+
},
349363
];
350364

351365
void describe('invokeCDKCommand', { concurrency: 1 }, () => {

packages/backend-deployer/src/cdk_error_mapper.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ export class CdkErrorMapper {
263263
errorName: 'BackendSynthError',
264264
classification: 'ERROR',
265265
},
266+
{
267+
// This happens when 'defineBackend' call is missing in customer's app.
268+
// 'defineBackend' creates CDK app in memory. If it's missing then no cdk.App exists in memory and nothing is rendered.
269+
// During 'cdk synth' CDK CLI attempts to read CDK assembly after calling customer's app.
270+
// But no files are rendered causing it to fail.
271+
errorRegex:
272+
/ENOENT: no such file or directory, open '\.amplify.artifacts.cdk\.out.manifest\.json'/,
273+
humanReadableErrorMessage:
274+
'The Amplify backend definition is missing `defineBackend` call.',
275+
resolutionMessage:
276+
'Check your backend definition in the `amplify` folder. Ensure that `amplify/backend.ts` contains `defineBackend` call.',
277+
errorName: 'MissingDefineBackendError',
278+
classification: 'ERROR',
279+
},
266280
{
267281
// "Catch all": the backend entry point file is referenced in the stack indicating a problem in customer code
268282
errorRegex: /amplify\/backend/,
@@ -317,11 +331,11 @@ export type CDKDeploymentError =
317331
| 'CFNUpdateNotSupportedError'
318332
| 'CloudFormationDeploymentError'
319333
| 'FilePermissionsError'
334+
| 'MissingDefineBackendError'
320335
| 'MultipleSandboxInstancesError'
321336
| 'ESBuildError'
322337
| 'ExpiredTokenError'
323338
| 'FileConventionError'
324-
| 'FileConventionError'
325339
| 'ModuleNotFoundError'
326340
| 'SecretNotSetError'
327341
| 'SyntaxError';

0 commit comments

Comments
 (0)