Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: specifically catch AppSync 'Code contains one or more errors' #2264

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/early-suits-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-deployer': patch
---

specifically catch AppSync "Code contains one or more errors"
12 changes: 10 additions & 2 deletions packages/backend-deployer/src/cdk_error_mapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ const testErrorMappings = [
expectedDownstreamErrorMessage: undefined,
},
{
errorMessage: `[31m some-stack failed: The stack named some-stack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: The code contains one or more errors. (Service: AppSync, Status Code: 400, Request ID: 12345) (RequestToken: 123, HandlerErrorCode: GeneralServiceException), Embedded stack <escaped ARN> was not successfully updated. Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: The following resource(s) failed to create: [resource1, resource2]. [39m`,
errorMessage: `[31m some-stack failed: The stack named some-stack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: Some amazing error message (Service: AppSync, Status Code: 400, Request ID: 12345) (RequestToken: 123, HandlerErrorCode: GeneralServiceException), Embedded stack <escaped ARN> was not successfully updated. Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: The following resource(s) failed to create: [resource1, resource2]. [39m`,
expectedTopLevelErrorMessage: 'The CloudFormation deployment has failed.',
errorName: 'CloudFormationDeploymentError',
expectedDownstreamErrorMessage: `The stack named some-stack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: The code contains one or more errors. (Service: AppSync, Status Code: 400, Request ID: 12345) (RequestToken: 123, HandlerErrorCode: GeneralServiceException), Embedded stack <escaped ARN> was not successfully updated. Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: The following resource(s) failed to create: [resource1, resource2]. [39m`,
expectedDownstreamErrorMessage: `The stack named some-stack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: Some amazing error message (Service: AppSync, Status Code: 400, Request ID: 12345) (RequestToken: 123, HandlerErrorCode: GeneralServiceException), Embedded stack <escaped ARN> was not successfully updated. Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: The following resource(s) failed to create: [resource1, resource2]. [39m`,
},
{
errorMessage: `[31m some-stack failed: The stack named some-stack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE`,
Expand Down Expand Up @@ -406,6 +406,14 @@ npm error A complete log of this run can be found in: /home/some-path/.npm/_logs
errorName: 'AccessDeniedError',
expectedDownstreamErrorMessage: undefined,
},
{
errorMessage: `amplify-stack-user-sandbox failed: BadRequestException: The code contains one or more errors.`,
expectedTopLevelErrorMessage:
'A custom resolver used in your defineData contains one or more errors',
errorName: 'AppSyncResolverSyntaxError',
expectedDownstreamErrorMessage:
'amplify-stack-user-sandbox failed: BadRequestException: The code contains one or more errors.',
},
{
errorMessage:
`Error: Transform failed with 1 error:` +
Expand Down
38 changes: 24 additions & 14 deletions packages/backend-deployer/src/cdk_error_mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,7 @@ export class CdkErrorMapper {
errorName: 'InvalidPackageJsonError',
classification: 'ERROR',
},
{
// Error: .* is printed to stderr during cdk synth
// Also extracts the first line in the stack where the error happened
errorRegex: new RegExp(
`^Error: (.*${this.multiLineEolRegex}.*at.*)`,
'm'
),
humanReadableErrorMessage:
'Unable to build the Amplify backend definition.',
resolutionMessage:
'Check your backend definition in the `amplify` folder for syntax and type errors.',
errorName: 'BackendSynthError',
classification: 'ERROR',
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just moved down in the order to catch more "generic" errors.


{
// This happens when 'defineBackend' call is missing in customer's app.
// 'defineBackend' creates CDK app in memory. If it's missing then no cdk.App exists in memory and nothing is rendered.
Expand Down Expand Up @@ -362,6 +349,28 @@ export class CdkErrorMapper {
errorName: 'SecretNotSetError',
classification: 'ERROR',
},
{
errorRegex: /The code contains one or more errors/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few thoughts:

  1. Is it possible to assert that this error is indeed from appsync, e.g. /The code contains one or more errors/.*AppSync. I would guess there are more services and tools that could throw such a generic message.
  2. This might also happen if defineData ships regression in one of our resolvers (like this one) OR if appsync breaks JS resolvers runtime. Is there a way to distinguish between these situations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Few internal/external searches revealed this is AppSync specific only. The error from hotswap is Error: �[31m �[1mamplify-redacted-stack-11111111111�[22m failed: BadRequestException: The code contains one or more errors.�[39m
  2. No, unfortunately the error messages have no distinguishable information

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.
Regarding 1.
Would /BadRequestException: The code contains one or more errors/ ? So that at least there's clear signal that message came from service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work either, the CFN error message is Deployment failed: Error: The stack named amplify-redacted-stack-1111111 failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: The code contains one or more errors. (Service: AppSync, Status Code: 400,...

We can do /BadRequestException: The code contains one or more errors|/The code contains one or more errors/.*AppSync/ if we want to be more specific

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated Regex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty

humanReadableErrorMessage: `A custom resolver used in your defineData contains one or more errors`,
resolutionMessage: `Check for any syntax errors in your custom resolvers code.`,
errorName: 'AppSyncResolverSyntaxError',
classification: 'ERROR',
},
// Generic error printed by CDK. Order matters so keep this towards the bottom of this list
{
// Error: .* is printed to stderr during cdk synth
// Also extracts the first line in the stack where the error happened
errorRegex: new RegExp(
`^Error: (.*${this.multiLineEolRegex}.*at.*)`,
'm'
),
humanReadableErrorMessage:
'Unable to build the Amplify backend definition.',
resolutionMessage:
'Check your backend definition in the `amplify` folder for syntax and type errors.',
errorName: 'BackendSynthError',
classification: 'ERROR',
},
{
errorRegex:
/(?<stackName>amplify-[a-z0-9-]+)(.*) failed: ValidationError: Stack:(.*) is in (?<state>.*) state and can not be updated/,
Expand All @@ -388,6 +397,7 @@ export class CdkErrorMapper {

export type CDKDeploymentError =
| 'AccessDeniedError'
| 'AppSyncResolverSyntaxError'
| 'BackendBuildError'
| 'BackendSynthError'
| 'BootstrapNotDetectedError'
Expand Down