AOSSIE-Org / AOSSIE-Org/PictoPy
BUG: Improve SQLite error handling in get_db_connection
- 主要語言
- Python
- 星號
- 283
- 分支
- 679
- 平均合併
- 7 天 2 小時
- 30 天內合併 PR
- 3
描述
### 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
貢獻指南
評估
這個 Issue 還沒有評估資料。