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

feat: Add database errors handlers to get better error messages (M2-8184) #1700

Conversation

rcmerlo
Copy link
Contributor

@rcmerlo rcmerlo commented Jan 2, 2025

  • Tests for the changes have been added
  • Related documentation has been added / updated
  • For new features, QA automation engineers have been tagged
  • OSS packages added to MindLogger open source credit page

📝 Description

Add new error handlers for database error to have better error messages in logs, this will help to fix any error related to arbitrary servers. It will keep returning http 500 status error

🔗 Jira Ticket M2-8184

Postman 2025-01-02 13 38 05 image

🪤 Peer Testing

Prepare environment:

  • Create a new postgresql instance, you can use docker to run it in another port or run in another host, can't be the same instance
  • Set arbitrary server point to this new postgresql instance
    python src/cli.py arbitrary add --db-uri postgresql+asyncpg://postgres:[email protected]/dev --storage-type aws --storage-secret-key fake --storage-access-key fake --storage-region us-east-1 --storage-bucket arbitrary OWNER_EMAIL --force
  • Run migrations in this new arbitrary server
    alembic -c alembic_arbitrary.ini upgrade head
  • Make sure everything is working
    python src/cli.py arbitrary show

To test connection refused error:

  • Start API server
  • Stop new postgresql instance
  • Request completions endpoint, check for error sand check logs message in API server

To test wrong password error:

  • Start API server and arbitrary server instance
  • Change postgresql password
  • Request completions endpoint, check for error sand check logs message in API server

✏️ Notes

To remove abritrary server, just call:
python src/cli.py arbitrary remove OWNER_EMAIL

@rcmerlo rcmerlo force-pushed the M2-8184-BE-Improve-how-the-BE-handles-wrong-arbitrary-server-settings-errors branch from 70f0512 to b2d815b Compare January 2, 2025 16:55
Copy link

github-actions bot commented Jan 2, 2025

➡️ Preview environment failed to be destroyed

Copy link

github-actions bot commented Jan 2, 2025

❌ E2E tests failed

Copy link
Contributor

@farmerpaul farmerpaul left a comment

Choose a reason for hiding this comment

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

Only one Pylance comment so far, code looks fine otherwise.

I'm struggling to figure out how to test this. I've tried misconfiguring the report server for an applet, but still not sure how to trigger the error. @rcmerlo would you mind filling out the 🪤 Peer Testing section from the PR description template? I know it's a little more work for you to do that, but it will help save the rest of us time during review. Thanks!

src/infrastructure/http/exceptions.py Outdated Show resolved Hide resolved
@farmerpaul
Copy link
Contributor

Also, the AC states:

If there is a wrong setting in the arbitrary server, the BE is able to handle it without crashing and returns a proper error message in the logs instead of a 500 error.

But your PR description states:

It will keep returning http 500 status error

Which one is correct?

@farmerpaul farmerpaul self-requested a review January 6, 2025 15:34
@rcmerlo
Copy link
Contributor Author

rcmerlo commented Jan 6, 2025

Also, the AC states:

If there is a wrong setting in the arbitrary server, the BE is able to handle it without crashing and returns a proper error message in the logs instead of a 500 error.

But your PR description states:

It will keep returning http 500 status error

Which one is correct?

@farmerpaul I remember we commented on planning for this ticket that we should keep API returning 500 to not break FE behavior, since users can't handle this kind of error, we should only report it in logs to help support team to fix it.

Pipfile Outdated Show resolved Hide resolved
src/infrastructure/http/exceptions.py Show resolved Hide resolved
@rcmerlo rcmerlo merged commit 80d4f80 into develop Jan 14, 2025
11 of 13 checks passed
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.

3 participants