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

fix: add cdk error mapping for error 'no valid tables found' #2319

Closed
wants to merge 3 commits into from

Conversation

awsluja
Copy link
Contributor

@awsluja awsluja commented Dec 11, 2024

Problem

At this time, 100% of errors with 'no valid tables found' error message are coming from the 'generate schema-from-database' command. This reclassifies that error as it is a user error, and resolution is to make sure a primary key is defined on at least one table in the database that is being imported/generated from.

see: https://docs.amplify.aws/javascript/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/#step-2---generate-typescript-representation-of-your-database-schema

Issue number, if available:

Changes

Corresponding docs PR, if applicable:

Validation

Validated that this is not reproducible with standard deployment commands, and found that all errors were coming from the generate schema-from-database command, which requires primary keys on at least one table.

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@awsluja awsluja requested a review from a team as a code owner December 11, 2024 21:48
Copy link

changeset-bot bot commented Dec 11, 2024

🦋 Changeset detected

Latest commit: 88fc41d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/backend-deployer Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines +489 to +498
{
errorRegex:
/No valid tables found\. Make sure at least one table has a primary key\./,
humanReadableErrorMessage:
'No valid tables found. Make sure at least one table has a primary key.',
resolutionMessage:
"If you are using the 'generate schema-from-database' command, make sure the database has at least one table with a primary key.",
errorName: 'GenerateSchemaFromDatabaseError',
classification: 'ERROR',
},
Copy link
Member

Choose a reason for hiding this comment

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

is backend-deployer involved in generate schema-from-database command ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we have error classification for non-deploy errors?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

But we should ask data team to throw typed error for this instead of attempting to match strings.

Copy link
Contributor

Choose a reason for hiding this comment

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

In cases like this I think we would want to catch and throw user error in SchemaGenerator or wherever makes sense. Unless we want to introduce error mapping for errors that can happen for CLI commands.

Copy link
Member

Choose a reason for hiding this comment

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

In cases like this I think we would want to catch and throw user error in SchemaGenerator

Correct. But it would be best if data team gave us better error to map from.

@@ -641,6 +641,13 @@ npm error enoent`,
errorName: 'CloudFormationDeletionError',
expectedDownstreamErrorMessage: undefined,
},
{
errorMessage: `No valid tables found. Make sure at least one table has a primary key.`,
Copy link
Contributor

Choose a reason for hiding this comment

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

I have 2 questions:

  1. took a brief look into this error, it comes from the data team's repo, from here: https://github.com/aws-amplify/amplify-category-api/blob/e4d16911236c5751e02609c8c3b069543535883a/packages/amplify-graphql-schema-generator/src/ts-schema-generator/helpers.ts#L176
    I think we have a few other non-cdk errors that are getting mapped in this file as well, just want to confirm that this is ok.
  2. You are committing some changes to package.lock. Is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looking into this more (thanks to Kamil's comment), it does seem that we don't have tooling in place for classifying anything other than what is coming from backend-deployer

also yes it seems package.lock is being updated on clean build but i can try again

@awsluja
Copy link
Contributor Author

awsluja commented Dec 11, 2024

closing for now, we need an alternative way to map these kind of errors

@awsluja awsluja closed this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants