Skip to content

Gen2 migrations QA fixes#14145

Merged
abhi7cr merged 3 commits intomigrationsfrom
gen2-migrations-execute
Mar 21, 2025
Merged

Gen2 migrations QA fixes#14145
abhi7cr merged 3 commits intomigrationsfrom
gen2-migrations-execute

Conversation

@abhi7cr
Copy link
Copy Markdown
Contributor

@abhi7cr abhi7cr commented Mar 21, 2025

Description of changes

  • Skip PreTokenGenerationConfig key from Cognito during prepare
  • Add new line to separate import, body and export statements in codegen
  • Wrap throw new Error call expression in a statement. This adds a semicolon at the end
  • Add @types/node to fix process.env type errors
  • Resolve CFN parameters in Gen2 stack during revert
  • Surface errors during Gen2 codegen in prepare command
  • Add support for --debug flag for prepare command to output the stack trace

Description of how you validated changes

local testing with prepare, execute and revert commands

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@abhi7cr abhi7cr requested review from a team as code owners March 21, 2025 06:05
(content) => {
return fileWriter(content, path.join(dirPath, 'resource.ts'))
.then(() => fileWriter('', path.join(dirPath, 'handler.ts')))
.catch(console.error);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was in the wrong place. It was intended to catch codegen errors but this is while writing code to the files.

expect(e).toBeInstanceOf(Error);
expect(printSpy).toBeCalledTimes(2);
expect(printSpy).toHaveBeenNthCalledWith(1, message);
expect(printSpy.mock.calls[1][0]).toContain('at Promise');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

at <Method call> is used to detect stack trace.

@abhi7cr abhi7cr changed the title Gen2 migrations execute Gen2 migrations QA fixes Mar 21, 2025
}

return factory.createNodeArray([...imports, ...errors, backendStatement, ...nodes], true);
return factory.createNodeArray([...imports, newLineIdentifier, ...errors, newLineIdentifier, backendStatement, ...nodes], true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice! We should do it in category specific resource.ts files too (in next CR)

Copy link
Copy Markdown

@surbhibansal surbhibansal Mar 21, 2025

Choose a reason for hiding this comment

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

nvm, saw later you have it already

}
});

it('should print error with debug flag', async () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: debug true right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question. Its not a boolean flag, the presence of --debug indicates its true and absence is false.

jest.clearAllMocks();
});

it('should print error without debug flag', async () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

with debug false?

`Source code for this function can be found in your Amplify Gen 1 Directory. See .amplify/migration/amplify/backend/function/${definition.resourceName}/src`,
),
]),
factory.createExpressionStatement(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should also wrap other throw new Error in createExpressionStatement(). We've some instances in backend.ts and also auth/resource.ts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call out. Will do it other places too.

@abhi7cr abhi7cr merged commit e4e37c8 into migrations Mar 21, 2025
5 checks passed
@abhi7cr abhi7cr deleted the gen2-migrations-execute branch March 21, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants