[Fix] #104 — Add error handling to startup event for init_db() - #127
Open
adarsh-gautam-sys wants to merge 1 commit into
Open
[Fix] #104 — Add error handling to startup event for init_db()#127adarsh-gautam-sys wants to merge 1 commit into
adarsh-gautam-sys wants to merge 1 commit into
Conversation
… for init_db()
|
@adarsh-gautam-sys is attempting to deploy a commit to the devloperdevesh's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
startup_eventinapp/main.pycalledinit_db()with no error handling. If the database was unreachable or misconfigured, the application would silently start in a broken state, causing cryptic runtime errors on every API call instead of a clear startup failure. This PR wrapsinit_db()in atry/exceptblock that logs the error and aborts startup with aRuntimeError.Root Cause
app/main.pystartup event calledinit_db()withouttry/except. Any exception during database initialisation was silently swallowed (or propagated non-fatally by FastAPI), allowing the application to start and appear healthy while the database remained uninitialized.Changes Made
app/main.py:import loggingand a module-levelloggerinit_db()call intry/except Exception; on failure, logs aCRITICALmessage and raisesRuntimeErrorto abort startupinit_redis()in a separatetry/except; Redis failure is logged asWARNING(non-fatal, degrades gracefully)app.core.*pathsHow to Test
DATABASE_URLto point to an unreachable database.uvicorn app.main:app --reloadRuntimeError: Startup aborted — database unavailableand aCRITICALlog line.INFOlog lines.Related Issue
Closes #104