Better exception formatting by tracerite #1865
Replies: 3 comments
-
|
I could hook up my handler to Expected: typer would use whatever handler is configured at the time of exception, not one it captured module level during import. Having this built into typer itself, replacing the pretty formatter it has, would also avoid the problem, although we still need to add separate support code within |
Beta Was this translation helpful? Give feedback.
-
|
Hi! Could you please first explain in more detail what the added advantage of doing this would be? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Example Code
# Not relevantDescription
I am looking to integrate Tracerite to FastAPI and consequently to this project, because it provides by far the best tracebacks that anyone has implemented for Python. The module formats for CLI, with colors, graphics and variable inspector similar to Typer's rich formatting, but also formats for HTML. Unlike others, it provides short to-the-point traceback with the relevant information in chronological order.
Wiring it up for HTML tracebacks on FastAPI is straight forward replacing Starlette ServerErrorMiddleware, but we also want to handle tracebacks on CLI, also during server startup, specifically including syntax errors and other such things that would fail early while loading the app. And this is where I discovered Typer as it is already wired to do that in the FastAPI stack.
For the console Tracerite hooks up sys.excepthook and also logging.exception. Typer is also grabbing the excepthook, but I see we could disable that from FastAPI side. Ideally we'd also hook somewhere between uvicorn.run and Config.load_app, such that we can handle those import and syntax errors, but there doesn't appear to be suitable hooks for this.
I will be making PR(s) on this, but I would like to have your insights first on where it would best be plugged in, and to which project I should make the PR to avoid monkey patching.
Hopefully you can shed some light on this so that I won't be working blindly.
Operating System
Other
Operating System Details
No response
Project Version
0.26.8
Python Version
No response
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions