Skip to content

Commit 0a360fb

Browse files
authored
fix: extract generic cdk asset publish failures (#2271)
1 parent 273a9ba commit 0a360fb

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

.changeset/poor-phones-attend.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+
extract generic cdk asset publish failures

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend-deployer/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"@aws-amplify/platform-core": "^1.2.2",
2323
"@aws-amplify/plugin-types": "^1.4.0",
2424
"execa": "^8.0.1",
25-
"tsx": "^4.6.1"
25+
"tsx": "^4.6.1",
26+
"strip-ansi": "^6.0.1"
2627
},
2728
"peerDependencies": {
2829
"aws-cdk": "^2.158.0",

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,24 @@ npm error A complete log of this run can be found in: /home/some-path/.npm/_logs
429429
errorName: 'AccessDeniedError',
430430
expectedDownstreamErrorMessage: undefined,
431431
},
432+
{
433+
// eslint-disable-next-line spellcheck/spell-checker
434+
errorMessage: `[31mamplify-stack-sandbox-11[22m: fail: Bucket named 'cdk-abc-assets-11-us-west-2' exists, but we do not have access to it.
435+
amplify-stack-sandbox-11: fail: Bucket named 'cdk-abc-assets-11-us-west-2' exists, but we do not have access to it.
436+
Failed to publish asset abc:current_account-current_region`,
437+
expectedTopLevelErrorMessage: `CDK failed to publish assets due to 'Bucket named 'cdk-abc-assets-11-us-west-2' exists, but we do not have access to it.'`,
438+
errorName: 'CDKAssetPublishError',
439+
expectedDownstreamErrorMessage: undefined,
440+
},
441+
{
442+
// eslint-disable-next-line spellcheck/spell-checker
443+
errorMessage: `[31mamplify-user-sandbox-c71414864a: fail: socket hang up
444+
445+
Failed to publish asset abc:current_account-current_region`,
446+
expectedTopLevelErrorMessage: `CDK failed to publish assets due to 'socket hang up'`,
447+
errorName: 'CDKAssetPublishError',
448+
expectedDownstreamErrorMessage: undefined,
449+
},
432450
{
433451
errorMessage:
434452
`Error: Transform failed with 1 error:` +

packages/backend-deployer/src/cdk_error_mapper.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AmplifyFault,
55
AmplifyUserError,
66
} from '@aws-amplify/platform-core';
7+
import stripANSI from 'strip-ansi';
78
import { BackendDeployerOutputFormatter } from './types.js';
89

910
/**
@@ -27,13 +28,14 @@ export class CdkErrorMapper {
2728
return amplifyError;
2829
}
2930

31+
const errorMessage = stripANSI(error.message);
3032
const matchingError = this.getKnownErrors().find((knownError) =>
31-
knownError.errorRegex.test(error.message)
33+
knownError.errorRegex.test(errorMessage)
3234
);
3335

3436
if (matchingError) {
3537
// Extract meaningful contextual information if available
36-
const matchGroups = error.message.match(matchingError.errorRegex);
38+
const matchGroups = errorMessage.match(matchingError.errorRegex);
3739

3840
if (matchGroups && matchGroups.length > 1) {
3941
// If the contextual information can be used in the error message use it, else consider it as a downstream cause
@@ -400,6 +402,16 @@ export class CdkErrorMapper {
400402
errorName: 'AppSyncResolverSyntaxError',
401403
classification: 'ERROR',
402404
},
405+
{
406+
errorRegex: new RegExp(
407+
`amplify-.*-(branch|sandbox)-.*fail: (?<publishFailure>.*)${this.multiLineEolRegex}.*Failed to publish asset`,
408+
'm'
409+
),
410+
humanReadableErrorMessage: `CDK failed to publish assets due to '{publishFailure}'`,
411+
resolutionMessage: `Check the error message for more details.`,
412+
errorName: 'CDKAssetPublishError',
413+
classification: 'ERROR',
414+
},
403415
// Generic error printed by CDK. Order matters so keep this towards the bottom of this list
404416
{
405417
// Error: .* is printed to stderr during cdk synth
@@ -447,6 +459,7 @@ export type CDKDeploymentError =
447459
| 'BootstrapNotDetectedError'
448460
| 'BootstrapDetectionError'
449461
| 'BootstrapOutdatedError'
462+
| 'CDKAssetPublishError'
450463
| 'CDKResolveAWSAccountError'
451464
| 'CDKVersionMismatchError'
452465
| 'CFNUpdateNotSupportedError'

0 commit comments

Comments
 (0)