Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Add custom handler of exceptions - #425

Merged
aponcedeleonch merged 1 commit into
mainfrom
exception-formatting
Dec 19, 2024
Merged

aponcedeleonch merged 1 commit into
mainfrom
exception-formatting

Conversation

@aponcedeleonch

Copy link
Copy Markdown
Member

This will change the way we visualize the Exceptions in FastAPI to a more traditional unformatted approach.

  File "/Users/aponcedeleonch/py_venvs/codegate_env/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 2505, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/Users/aponcedeleonch/py_venvs/codegate_env/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 1005, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aponcedeleonch/StacklokRepos/codegate/src/codegate/dashboard/dashboard.py", line 35, in get_messages
    raise Exception("This is a test exception")
2024-12-19T13:45:25.3dZ [error    ] module=server pathname=/Users/aponcedeleonch/StacklokRepos/codegate/src/codegate/server.py
2024-12-19T13:45:25.3dZ [info     ] ::1:59820 - "GET /dashboard/messages HTTP/1.1" 500 module=h11_impl pathname=/Users/aponcedeleonch/py_venvs/codegate_env/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py

The advantage would be that we would no longer get really long exceptions from FastAPI

This will change the way we visualize the Exceptions in FastAPI to a more
traditional unformatted approach.
```
  File "/Users/aponcedeleonch/py_venvs/codegate_env/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 2505, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/Users/aponcedeleonch/py_venvs/codegate_env/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 1005, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aponcedeleonch/StacklokRepos/codegate/src/codegate/dashboard/dashboard.py", line 35, in get_messages
    raise Exception("This is a test exception")
2024-12-19T13:45:25.3dZ [error    ] module=server pathname=/Users/aponcedeleonch/StacklokRepos/codegate/src/codegate/server.py
2024-12-19T13:45:25.3dZ [info     ] ::1:59820 - "GET /dashboard/messages HTTP/1.1" 500 module=h11_impl pathname=/Users/aponcedeleonch/py_venvs/codegate_env/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py
```

The advantage would be that we would no longer get really long exceptions from FastAPI
@aponcedeleonch

Copy link
Copy Markdown
Member Author

This is mostly cosmetic. Will leave it here but feel free to close without merging

@ptelang ptelang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@aponcedeleonch
aponcedeleonch merged commit 89e2684 into main Dec 19, 2024
@aponcedeleonch
aponcedeleonch deleted the exception-formatting branch December 19, 2024 21:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants