Skip to content

Commit c85d071

Browse files
ShadowCat567Vieltojarvi
and
Vieltojarvi
authored
Activate prefer-amplify-errors (#1986)
* activated prefer-amplify-errors in some packages * updated prefer-amplify-errors to ignore non-throw statements * ignore violation in backend-deployer * added changeset * reverted prefer-amplify-errors, added inline ignores to backend-auth and -ai * updated changeset --------- Co-authored-by: Vieltojarvi <[email protected]>
1 parent 8e964e1 commit c85d071

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

.changeset/eight-beers-stare.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@aws-amplify/backend-deployer': patch
3+
'create-amplify': patch
4+
'@aws-amplify/backend-auth': patch
5+
'@aws-amplify/backend-ai': patch
6+
---
7+
8+
updated packages to fix violations of prefer-amplify-errors rule

packages/backend-ai/src/conversation/factory.ts

+1
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,5 @@ export type DefineConversationHandlerFunctionProps = {
143143
export const defineConversationHandlerFunction = (
144144
props: DefineConversationHandlerFunctionProps
145145
): ConstructFactory<ResourceProvider<FunctionResources>> =>
146+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
146147
new ConversationHandlerFunctionFactory(props, new Error().stack);

packages/backend-auth/src/factory.ts

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class AmplifyAuthFactory implements ConstructFactory<BackendAuth> {
7979
*/
8080
constructor(
8181
private readonly props: AmplifyAuthProps,
82+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
8283
private readonly importStack = new Error().stack
8384
) {
8485
if (AmplifyAuthFactory.factoryCount > 0) {
@@ -235,4 +236,5 @@ const roleNameIsAuthRoleName = (roleName: string): roleName is AuthRoleName => {
235236
export const defineAuth = (
236237
props: AmplifyAuthProps
237238
): ConstructFactory<BackendAuth> =>
239+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
238240
new AmplifyAuthFactory(props, new Error().stack);

packages/backend-deployer/src/cdk_deployer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export class CDKDeployer implements BackendDeployer {
199199
// However if the cdk process didn't run or produced no output, then we have nothing to go on with. So we throw
200200
// this error to aid in some debugging.
201201
if (aggregatedStderr.trim()) {
202+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
202203
throw new Error(aggregatedStderr);
203204
} else {
204205
throw error;

packages/create-amplify/src/project_root_validator.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AmplifyUserError } from '@aws-amplify/platform-core';
12
import { existsSync } from 'fs';
23
import * as path from 'path';
34

@@ -22,9 +23,10 @@ export class ProjectRootValidator {
2223
validate = async (): Promise<void> => {
2324
const testPath = path.resolve(this.projectRoot, 'amplify');
2425
if (this.exists(testPath)) {
25-
throw new Error(
26-
`An amplify directory already exists at ${testPath}. If you are trying to run an Amplify Gen 2 command inside an Amplify Gen 1 project we recommend creating the project in another directory. Learn more about AWS Amplify Gen 2: ${amplifyLearnMoreUrl}`
27-
);
26+
throw new AmplifyUserError('AmplifyDirectoryAlreadyExistsError', {
27+
message: `An amplify directory already exists at ${testPath}.`,
28+
resolution: `If you are trying to run an Amplify Gen 2 command inside an Amplify Gen 1 project we recommend creating the project in another directory. Learn more about AWS Amplify Gen 2: ${amplifyLearnMoreUrl}`,
29+
});
2830
}
2931
};
3032
}

packages/eslint-rules/src/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ export const configs = {
2121
},
2222
overrides: [
2323
{
24-
files: ['packages/cli/src/**'],
24+
files: [
25+
'packages/sandbox/src/**',
26+
'packages/backend-ai/src/**',
27+
'packages/backend-auth/src/**',
28+
'packages/backend-deployer/src/**',
29+
'packages/create-amplify/src/**',
30+
],
2531
excludedFiles: ['**/*.test.ts'],
2632
rules: {
27-
'amplify-backend-rules/prefer-amplify-errors': 'off', //will be changed to 'error' in the future
33+
'amplify-backend-rules/prefer-amplify-errors': 'error',
2834
},
2935
},
3036
{

0 commit comments

Comments
 (0)