AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: Improve SQLite error handling in get_db_connection

Aberta
#1,102 5 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
283
Forks
679
Merge médio
7d 2h
PRs com merge (30d)
3

Descrição

### Is there an existing issue for this?

- [x] 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

- [x] I agree to follow this project's Code of Conduct

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.