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

Implemented no-amplify-errors in packages where it should be active #1973

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions .changeset/happy-adults-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@aws-amplify/schema-generator': patch
'@aws-amplify/model-generator': patch
---

activated no-amplify-errors, ignored lines with valid violations
10 changes: 9 additions & 1 deletion packages/eslint-rules/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ export const configs = {
},
},
{
files: ['packages/auth-construct/src/**'],
files: [
'packages/auth-construct/src/**',
'packages/ai-constructs/src/**',
'packages/backend-output-storage/src/**',
'packages/deployed-backend-client/src/**',
'packages/form-generator/src/**',
'packages/model-generator/src/**',
'packages/schema-generator/src/**',
],
rules: {
'amplify-backend-rules/no-amplify-errors': 'error',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const getBackendOutputWithErrorHandling = async (
error instanceof BackendOutputClientError &&
error.code === BackendOutputClientErrorType.DEPLOYMENT_IN_PROGRESS
) {
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
Copy link
Member

@sobolk sobolk Sep 10, 2024

Choose a reason for hiding this comment

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

Now that I see the code around the suppression I do wonder what we should do about this long term.

  1. Should we be moving the error handling like this up? I.e. move this to relevant CLI commands instead of having this handling here?
  2. Should we re-classify this package (and other X-generators) and apply prefer-amplify-errors instead and keep local mapping at this level?

I would say 1. seems to be more correct. And I think lifting all these mappings to cli would be applicable to any command that pulls outputs. These don't seem to be specific to model generation.

@Amplifiyer @rtpascual what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm leaning towards 1 as well since this is already done for the ampx generate form command https://github.com/aws-amplify/amplify-backend/blob/main/packages/cli/src/commands/generate/forms/generate_forms_command.ts#L75-L137.

I believe moving this file to cli will get rid of the need for the duplicate code for forms as a side effect.

Copy link
Member

Choose a reason for hiding this comment

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

Btw. if we align on number 1 then this PR should go as is and work item should be opened to move this handling up separately.

throw new AmplifyUserError(
'DeploymentInProgressError',
{
Expand All @@ -33,6 +34,7 @@ export const getBackendOutputWithErrorHandling = async (
error instanceof BackendOutputClientError &&
error.code === BackendOutputClientErrorType.NO_STACK_FOUND
) {
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
throw new AmplifyUserError(
'StackDoesNotExistError',
{
Expand All @@ -47,6 +49,7 @@ export const getBackendOutputWithErrorHandling = async (
error instanceof BackendOutputClientError &&
error.code === BackendOutputClientErrorType.CREDENTIALS_ERROR
) {
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
throw new AmplifyUserError(
'CredentialsError',
{
Expand All @@ -61,6 +64,7 @@ export const getBackendOutputWithErrorHandling = async (
error instanceof BackendOutputClientError &&
error.code === BackendOutputClientErrorType.ACCESS_DENIED
) {
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
throw new AmplifyUserError(
'AccessDeniedError',
{
Expand Down
3 changes: 3 additions & 0 deletions packages/schema-generator/src/generate_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class SchemaGenerator {
} catch (err) {
const databaseError = err as DatabaseConnectError;
if (databaseError.code === 'ETIMEDOUT') {
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
throw new AmplifyUserError<AmplifyGenerateSchemaError>(
'DatabaseConnectionError',
{
Expand Down Expand Up @@ -117,6 +118,7 @@ export const parseDatabaseUrl = (databaseUrl: string): SQLDataSourceConfig => {
).filter((part) => !config[part]);

if (missingParts.length > 0) {
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
throw new AmplifyUserError<AmplifyGenerateSchemaError>(
'DatabaseUrlParseError',
{
Expand All @@ -132,6 +134,7 @@ export const parseDatabaseUrl = (databaseUrl: string): SQLDataSourceConfig => {
return config;
} catch (err) {
const error = err as Error;
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
throw new AmplifyUserError<AmplifyGenerateSchemaError>(
'DatabaseUrlParseError',
{
Expand Down