Narrow broad except Exception handlers to specific types#8
Conversation
Separate known processing errors (ValueError, RuntimeError, TypeError) from unexpected errors in route handlers, health check, and lifespan. Known errors log at WARNING level; unexpected errors log full tracebacks at ERROR level for investigation. This improves observability without changing user-facing behavior.
Greptile SummaryThis PR refines broad Changes:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Request arrives at route handler] --> B{Processing}
B -->|Success| C[Return HTML fragment / PDF]
B -->|ValueError / RuntimeError / TypeError| D[log.WARNING with error message]
D --> E[Return error_fragment.html — HTTP 200 or 500]
B -->|Any other Exception| F[log.ERROR with full traceback]
F --> E
subgraph health.py [health.py check_health]
H[get_analyzer] -->|ImportError / OSError / RuntimeError / ValueError| I[log.WARNING → status=degraded]
H -->|Other Exception NEW| J[⚠️ Propagates as 500]
H -->|Success| K[analyzer_ready=true]
end
subgraph lifespan [app.py lifespan]
L[get_analyzer] -->|ImportError / OSError / RuntimeError / ValueError| M[log.EXCEPTION → raise → app fails to start]
L -->|Other Exception NEW| N[⚠️ No structured log → raise → app fails to start]
L -->|Success| O[yield — app starts]
end
|
Summary
ValueError,RuntimeError,TypeError) from unexpected errors in 3 route handlers, health check, and app lifespanhealth.pyandapp.pylifespan now catch(ImportError, OSError, RuntimeError, ValueError)for model loading failuresTest plan
make checkpasses (275 tests, 95.58% coverage)