You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This time I have noticed that changing MyExc(Exception) to MyExc(BaseException) means the error does get sent to stdout (if that helps) I tried to have a dig but I am not too sure where that catch exception is that is catching the Exception (and silently passing) and not the BaseException
starlette==0.37.2
fastapi==0.111.0
importuvicornfromfastapiimportFastAPIfromstarlette.middleware.baseimportBaseHTTPMiddlewareapp=FastAPI()
classMyExc(Exception): # change to BaseException and then both exceptions are sent to stdout
...
@app.get("/info")definfo():
# raises Exception as expected, the traceback is seen in consoleraiseMyExcprivate_api=FastAPI()
@private_api.get("/info")definfo():
# exception is handled silently, no traceback is seen in consoleraiseMyExcapp.mount("/private", private_api)
classMiddleware(BaseHTTPMiddleware):
asyncdefdispatch(self, request, call_next):
returnawaitcall_next(request)
app.add_middleware(Middleware) # when this is removed, the exceptions are raised for all routesif__name__=="__main__":
uvicorn.run(app, port=8000)
Important
We're using Polar.sh so you can upvote and help fund this issue.
We receive the funding once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
The text was updated successfully, but these errors were encountered:
@daniilmastrangeli a fix I have found for now is to add_exception_handler which catches the exception and if re-raised will display the trace to stdout as expected
importuvicornfromfastapiimportFastAPI, Requestfromstarlette.middleware.baseimportBaseHTTPMiddlewareapp=FastAPI()
classMyExc(Exception):
...
@app.get("/info")definfo():
raiseMyExcprivate_api=FastAPI()
@private_api.get("/info")definfo():
raiseMyExcapp.mount("/private", private_api)
classMiddleware(BaseHTTPMiddleware):
asyncdefdispatch(self, request, call_next):
returnawaitcall_next(request)
defre_raise_exception(_: Request, exc: Exception):
raiseexcfromexcapp.add_middleware(Middleware)
app.add_exception_handler(Exception, re_raise_exception) # raises the exception in the handler which results in getting handled by a different contextif__name__=="__main__":
uvicorn.run(app, port=8000)
Regression of #1976 #1977 #1609 #1940
This time I have noticed that changing
MyExc(Exception)
toMyExc(BaseException)
means the error does get sent to stdout (if that helps) I tried to have a dig but I am not too sure where that catch exception is that is catching the Exception (and silently passing) and not the BaseExceptionstarlette==0.37.2
fastapi==0.111.0
Important
The text was updated successfully, but these errors were encountered: