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

Activate prefer-amplify-errors #1986

Merged
merged 7 commits into from
Sep 11, 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
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