BUG: Improve SQLite error handling in get_db_connection

Open Beginner friendly
#1,102 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python, sqlite
Domain
backend, database

Research direction

Start in backend/app/database/connection.py at get_db_connection and inspect how database operations currently catch exceptions, log failures, roll back, and re-raise. Replace the broad handling with SQLite-specific handling while preserving rollback and re-raise behavior; done means unrelated exceptions are not caught and database failures have useful logging context.

Written by the indexing model from the issue text.

Description

Is there an existing issue for this?
  • I have searched the existing issues
What happened?
Problem

The current implementation of get_db_connection in backend/app/database/connection.py catches a broad Exception when handling database operations.

Catching all exceptions can:

  • Hide SQLite-specific errors
  • Make debugging more difficult
  • Handle unrelated runtime errors in a place meant only for database failures
  • Provide no logging context when a transaction fails
Why this matters

More precise error handling improves:

  • Debuggability for contributors
  • Code clarity and maintainability
  • Reliability of database transaction management
  • Alignment with Python and database best practices
Proposed improvement

Refine the exception handling to:

  • Catch sqlite3.Error instead of a generic Exception
  • Log database-related failures for better visibility
  • Preserve the existing rollback and re-raise behavior

This change does not affect application logic but improves robustness and developer experience.

I would be happy to open a PR with this improvement if maintainers agree.

Record
  • I agree to follow this project's Code of Conduct
Dominant language
Python
Stars
289
Forks
685
Avg merge
4d 6h
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AOSSIE-Org/PictoPy

All issues in AOSSIE-Org/PictoPy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.