Skip to content

Commit

Permalink
Activate prefer-amplify-errors (#1986)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ShadowCat567 and Vieltojarvi authored Sep 11, 2024
1 parent 8e964e1 commit c85d071
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .changeset/eight-beers-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@aws-amplify/backend-deployer': patch
'create-amplify': patch
'@aws-amplify/backend-auth': patch
'@aws-amplify/backend-ai': patch
---

updated packages to fix violations of prefer-amplify-errors rule
1 change: 1 addition & 0 deletions packages/backend-ai/src/conversation/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ export type DefineConversationHandlerFunctionProps = {
export const defineConversationHandlerFunction = (
props: DefineConversationHandlerFunctionProps
): ConstructFactory<ResourceProvider<FunctionResources>> =>
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
new ConversationHandlerFunctionFactory(props, new Error().stack);
2 changes: 2 additions & 0 deletions packages/backend-auth/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class AmplifyAuthFactory implements ConstructFactory<BackendAuth> {
*/
constructor(
private readonly props: AmplifyAuthProps,
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
private readonly importStack = new Error().stack
) {
if (AmplifyAuthFactory.factoryCount > 0) {
Expand Down Expand Up @@ -235,4 +236,5 @@ const roleNameIsAuthRoleName = (roleName: string): roleName is AuthRoleName => {
export const defineAuth = (
props: AmplifyAuthProps
): ConstructFactory<BackendAuth> =>
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
new AmplifyAuthFactory(props, new Error().stack);
1 change: 1 addition & 0 deletions packages/backend-deployer/src/cdk_deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class CDKDeployer implements BackendDeployer {
// However if the cdk process didn't run or produced no output, then we have nothing to go on with. So we throw
// this error to aid in some debugging.
if (aggregatedStderr.trim()) {
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
throw new Error(aggregatedStderr);
} else {
throw error;
Expand Down
8 changes: 5 additions & 3 deletions packages/create-amplify/src/project_root_validator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AmplifyUserError } from '@aws-amplify/platform-core';
import { existsSync } from 'fs';
import * as path from 'path';

Expand All @@ -22,9 +23,10 @@ export class ProjectRootValidator {
validate = async (): Promise<void> => {
const testPath = path.resolve(this.projectRoot, 'amplify');
if (this.exists(testPath)) {
throw new Error(
`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}`
);
throw new AmplifyUserError('AmplifyDirectoryAlreadyExistsError', {
message: `An amplify directory already exists at ${testPath}.`,
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}`,
});
}
};
}
10 changes: 8 additions & 2 deletions packages/eslint-rules/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ export const configs = {
},
overrides: [
{
files: ['packages/cli/src/**'],
files: [
'packages/sandbox/src/**',
'packages/backend-ai/src/**',
'packages/backend-auth/src/**',
'packages/backend-deployer/src/**',
'packages/create-amplify/src/**',
],
excludedFiles: ['**/*.test.ts'],
rules: {
'amplify-backend-rules/prefer-amplify-errors': 'off', //will be changed to 'error' in the future
'amplify-backend-rules/prefer-amplify-errors': 'error',
},
},
{
Expand Down

0 comments on commit c85d071

Please sign in to comment.