Skip to content

Commit e325044

Browse files
authored
Prefer amplify errors in generators (#2035)
1 parent 7aad5e8 commit e325044

15 files changed

+48
-11
lines changed

.changeset/forty-squids-help.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@aws-amplify/schema-generator': patch
3+
'@aws-amplify/model-generator': patch
4+
'@aws-amplify/form-generator': patch
5+
---
6+
7+
Prefer amplify errors in generators

packages/eslint-rules/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export const configs = {
2727
'packages/backend-auth/src/**',
2828
'packages/backend-deployer/src/**',
2929
'packages/create-amplify/src/**',
30+
'packages/form-generator/src/**',
31+
'packages/model-generator/src/**',
32+
'packages/schema-generator/src/**',
3033
],
3134
excludedFiles: ['**/*.test.ts'],
3235
rules: {
@@ -39,9 +42,6 @@ export const configs = {
3942
'packages/ai-constructs/src/**',
4043
'packages/backend-output-storage/src/**',
4144
'packages/deployed-backend-client/src/**',
42-
'packages/form-generator/src/**',
43-
'packages/model-generator/src/**',
44-
'packages/schema-generator/src/**',
4545
],
4646
rules: {
4747
'amplify-backend-rules/no-amplify-errors': 'error',

packages/form-generator/src/local_codegen_graphql_form_generator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,13 @@ export class LocalGraphqlFormGenerator implements GraphqlFormGenerator {
222222
([key]) => key.toLowerCase() === model.toLowerCase()
223223
);
224224
if (!entry) {
225+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
225226
throw new Error(`Could not find specified model ${model}`);
226227
}
227228
prev.push(entry);
228229
return prev;
229230
}
231+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
230232
throw new Error(`Could not find specified model ${model}`);
231233
},
232234
[]

packages/form-generator/src/s3_string_object_fetcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class S3StringObjectFetcher {
1919
);
2020
const schema = await getSchemaCommandResult.Body?.transformToString();
2121
if (!schema) {
22+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
2223
throw new Error('Error on parsing output schema');
2324
}
2425
return schema;

packages/model-generator/src/create_graphql_document_generator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ export const createGraphqlDocumentGenerator = ({
2929
awsClientProvider,
3030
}: GraphqlDocumentGeneratorFactoryParams): GraphqlDocumentGenerator => {
3131
if (!backendIdentifier) {
32+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
3233
throw new Error('`backendIdentifier` must be defined');
3334
}
3435
if (!awsClientProvider) {
36+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
3537
throw new Error('`awsClientProvider` must be defined');
3638
}
3739

@@ -44,6 +46,7 @@ export const createGraphqlDocumentGenerator = ({
4446
);
4547
const apiId = output[graphqlOutputKey]?.payload.awsAppsyncApiId;
4648
if (!apiId) {
49+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
4750
throw new Error(`Unable to determine AppSync API ID.`);
4851
}
4952

packages/model-generator/src/create_graphql_models_generator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ const createGraphqlModelsGeneratorFromBackendIdentifier = ({
6161
awsClientProvider,
6262
}: GraphqlModelsFromBackendIdentifierParams): GraphqlModelsGenerator => {
6363
if (!backendIdentifier) {
64+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
6465
throw new Error('`backendIdentifier` must be defined');
6566
}
6667
if (!awsClientProvider) {
68+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
6769
throw new Error('`awsClientProvider` must be defined');
6870
}
6971

@@ -90,9 +92,11 @@ export const createGraphqlModelsFromS3UriGenerator = ({
9092
awsClientProvider,
9193
}: GraphqlModelsFromS3UriGeneratorFactoryParams): GraphqlModelsGenerator => {
9294
if (!modelSchemaS3Uri) {
95+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
9396
throw new Error('`modelSchemaS3Uri` must be defined');
9497
}
9598
if (!awsClientProvider) {
99+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
96100
throw new Error('`awsClientProvider` must be defined');
97101
}
98102
return new StackMetadataGraphqlModelsGenerator(
@@ -118,6 +122,7 @@ const getModelSchema = async (
118122
const modelSchemaS3Uri =
119123
output[graphqlOutputKey]?.payload.amplifyApiModelSchemaS3Uri;
120124
if (!modelSchemaS3Uri) {
125+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
121126
throw new Error(`Cannot find model schema at amplifyApiModelSchemaS3Uri`);
122127
}
123128

packages/model-generator/src/create_graphql_types_generator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ export const createGraphqlTypesGenerator = ({
2929
awsClientProvider,
3030
}: GraphqlTypesGeneratorFactoryParams): GraphqlTypesGenerator => {
3131
if (!backendIdentifier) {
32+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
3233
throw new Error('`backendIdentifier` must be defined');
3334
}
3435
if (!awsClientProvider) {
36+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
3537
throw new Error('`awsClientProvider` must be defined');
3638
}
3739

@@ -44,6 +46,7 @@ export const createGraphqlTypesGenerator = ({
4446
);
4547
const apiId = output[graphqlOutputKey]?.payload.awsAppsyncApiId;
4648
if (!apiId) {
49+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
4750
throw new Error(`Unable to determine AppSync API ID.`);
4851
}
4952

packages/model-generator/src/generate_api_code.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class ApiCodeGenerator {
145145
return this.generateIntrospectionApiCode();
146146
}
147147
default:
148+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
148149
throw new Error(
149150
`${
150151
(props as GenerateApiCodeProps).format as string

packages/model-generator/src/get_backend_output_with_error_handling.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export const getBackendOutputWithErrorHandling = async (
2020
error instanceof BackendOutputClientError &&
2121
error.code === BackendOutputClientErrorType.DEPLOYMENT_IN_PROGRESS
2222
) {
23-
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
2423
throw new AmplifyUserError(
2524
'DeploymentInProgressError',
2625
{
@@ -34,7 +33,6 @@ export const getBackendOutputWithErrorHandling = async (
3433
error instanceof BackendOutputClientError &&
3534
error.code === BackendOutputClientErrorType.NO_STACK_FOUND
3635
) {
37-
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
3836
throw new AmplifyUserError(
3937
'StackDoesNotExistError',
4038
{
@@ -49,7 +47,6 @@ export const getBackendOutputWithErrorHandling = async (
4947
error instanceof BackendOutputClientError &&
5048
error.code === BackendOutputClientErrorType.CREDENTIALS_ERROR
5149
) {
52-
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
5350
throw new AmplifyUserError(
5451
'CredentialsError',
5552
{
@@ -64,7 +61,6 @@ export const getBackendOutputWithErrorHandling = async (
6461
error instanceof BackendOutputClientError &&
6562
error.code === BackendOutputClientErrorType.ACCESS_DENIED
6663
) {
67-
// eslint-disable-next-line amplify-backend-rules/no-amplify-errors
6864
throw new AmplifyUserError(
6965
'AccessDeniedError',
7066
{

packages/model-generator/src/graphql_document_generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class AppSyncGraphqlDocumentGenerator
2727
const schema = await this.fetchSchema();
2828

2929
if (!schema) {
30+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
3031
throw new Error('Invalid schema');
3132
}
3233

0 commit comments

Comments
 (0)