Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exception to include CORS middleware #243

Merged
merged 11 commits into from
Nov 21, 2023

Conversation

cosmastech
Copy link
Contributor

To resolve #240

@cosmastech cosmastech marked this pull request as draft November 19, 2023 18:36
@cosmastech cosmastech marked this pull request as ready for review November 19, 2023 20:03
@da-ekchajzer da-ekchajzer changed the base branch from main to dev November 19, 2023 21:43
@da-ekchajzer
Copy link
Collaborator

Thank you very much for your PR. Would it be possible to log the stack trace when error is catch ?

@cosmastech
Copy link
Contributor Author

Thank you very much for your PR. Would it be possible to log the stack trace when error is catch ?

@da-ekchajzer Do we need to include any kind of logging set up or is this sufficient?

@da-ekchajzer
Copy link
Collaborator

@da-ekchajzer Do we need to include any kind of logging set up or is this sufficient?

Ok for me

Thanks for this update, we can consider #240 solved. I am not familiar with error handling in starlette, but the logger logs the following error before logging the excpeted error.

Traceback (most recent call last):
  File "/home/da-ekchajzer/.cache/pypoetry/virtualenvs/boaviztapi-Sm2B5gn3-py3.10/lib/python3.10/site-packages/starlette/middleware/base.py", line 78, in call_next
    message = await recv_stream.receive()
  File "/home/da-ekchajzer/.cache/pypoetry/virtualenvs/boaviztapi-Sm2B5gn3-py3.10/lib/python3.10/site-packages/anyio/streams/memory.py", line 98, in receive
    return self.receive_nowait()
  File "/home/da-ekchajzer/.cache/pypoetry/virtualenvs/boaviztapi-Sm2B5gn3-py3.10/lib/python3.10/site-packages/anyio/streams/memory.py", line 91, in receive_nowait
    raise EndOfStream
anyio.EndOfStream
During handling of the above exception, another exception occurred:

[The expected error]

I don't think it's an important problem, but just checking if you have any idea on the reason of this error.

@cosmastech
Copy link
Contributor Author

I noticed the same thing. I'm quite new to Python, but I think this is an issue with how Starlette is handling the errors in anyio.memory.MemoryObjectReceiveStream. What I've done is remove this context from the traceback if the context of the Exception is anyio.EndOfStream.

@da-ekchajzer
Copy link
Collaborator

da-ekchajzer commented Nov 21, 2023

Great, thank you very much for your contribution.

@da-ekchajzer da-ekchajzer merged commit 3b14ed6 into Boavizta:dev Nov 21, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Catch errors instead of returning CORS errors to users
2 participants