Closed euri10 closed 1 year ago
if it helps and I'm correct debugging this, it seems to fail rendering the template with the last frame
FrameInfo(frame=<frame at 0x55caef072920, file 'asyncpg/protocol/protocol.pyx', line 168, code prepare>, filename='asyncpg/protocol/protocol.pyx', lineno=168, function='prepare', code_context=None, index=None)
it is as if in code_snippet.html
here {% for line in frame.code_context|default([]) %}
was not doing its job defaulting to an empty list
Can you share a code snippet to reproduce? Thanks
Okay, seems I found the error.
Can you change that line to {% for line in frame.code_context|default([], true) %}
and try again?
It got that error fixed.
Try 0.2.0
. Please see the README, the middleware was removed in favor of exception handler.
Try
0.2.0
. Please see the README, the middleware was removed in favor of exception handler.
I tried hard but cant run the exception handler now with that new api, let me expain, I'm using a probably weird setup but here it is with a simplified version.
I run uvicorn mm:app --reload
then mm.py
contains:
from ma import get_app
app = get_app()
and ma.py
contains
from fastapi import FastAPI
from starception import exception_handler
from starlette.requests import Request
from starlette.responses import Response
def get_app() -> FastAPI:
app = FastAPI( debug=True)
# def custom_exception_handler(request: Request, exc: Exception) -> Response:
# return exception_handler(request, exc, debug=True)
# app.add_exception_handler(Exception, custom_exception_handler)
@app.exception_handler(Exception)
def custom_exception_handler(request: Request, exc: Exception) -> Response:
return exception_handler(request, exc, debug=True)
from r import router as r
app.include_router(r)
return app
finally r.py
contains
from fastapi import APIRouter
from starlette.requests import Request
router = APIRouter()
@router.get("/")
async def index(request: Request):
raise TypeError("toto")
technically I could also run uvicorn ma:get_app --factory --reload
The issue is that the starception
template is not used, I see the Starlette one.
I'm not sure where it happens that I cannot get to it, without that factory the starception template is well displayed, if you have an idea I'm all ears ))
Okay, I see the problem. Starlette does not call custom error handlers when debug=True
instead, it always uses default.
Published 0.3. Consult docs (you need to use middleware again until).
Upstream issue https://github.com/encode/starlette/issues/1802
ok I think 0.3.0 fixed the asyncpg error frame not having a code_context
however I have another problem, but I think I'll open another issue,
it is because Im using starsessions, hey you write good stuff so I have to :) and there is sonehting in the template messing up with it, in {{ lib.details_row('Session', session) }}
I'll post a minimal example in another issue tomorrow, as for this one it's tested and fixed, thanks for the amazing look on the debug page !!
greetings, wanted to try this with an asyncpg error I was debugging, the below raise an exception and I have the classical Starlette template outputing fine,
but as soon as I add the middleware with
app.add_middleware(StarceptionMiddleware, debug=True)
I get no template and a Internal Server Error 500 page, and this error, not sure the issue is here or in Starlette itself though