zmievsa / cadwyn

Production-ready community-driven modern Stripe-like API versioning in FastAPI
https://docs.cadwyn.dev/
MIT License
186 stars 24 forks source link

BUG: Returning error 500 throws a `LocalProtocolError` #152

Closed isaacharrisholt closed 4 months ago

isaacharrisholt commented 4 months ago

Describe the bug A clear and concise description of what the bug is. If error stacktrace is available, include it here as well.

Stacktrace ``` Exception in ASGI application + Exception Group Traceback (most recent call last): | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 192, in __call__ | await response(scope, wrapped_receive, send) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/responses.py", line 257, in __call__ | async with anyio.create_task_group() as task_group: | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 678, in __aexit__ | raise BaseExceptionGroup( | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 412, in run_asgi | result = await app( # type: ignore[func-returns-value] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__ | return await self.app(scope, receive, send) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__ | await super().__call__(scope, receive, send) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__ | await self.middleware_stack(scope, receive, send) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__ | raise exc | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__ | await self.app(scope, receive, _send) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 189, in __call__ | with collapse_excgroups(): | File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 158, in __exit__ | self.gen.throw(value) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 93, in collapse_excgroups | raise exc | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/responses.py", line 260, in wrap | await func() | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 217, in stream_response | return await super().stream_response(send) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/responses.py", line 254, in stream_response | await send({"type": "http.response.body", "body": b"", "more_body": False}) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 161, in _send | await send(message) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 516, in send | output = self.conn.send(event=h11.EndOfMessage()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_connection.py", line 512, in send | data_list = self.send_with_data_passthrough(event) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_connection.py", line 545, in send_with_data_passthrough | writer(event, data_list.append) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_writers.py", line 67, in __call__ | self.send_eom(event.headers, write) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_writers.py", line 96, in send_eom | raise LocalProtocolError("Too little data for declared Content-Length") | h11._util.LocalProtocolError: Too little data for declared Content-Length +------------------------------------ During handling of the above exception, another exception occurred: + Exception Group Traceback (most recent call last): | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 87, in collapse_excgroups | yield | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 190, in __call__ | async with anyio.create_task_group() as task_group: | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 678, in __aexit__ | raise BaseExceptionGroup( | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Exception Group Traceback (most recent call last): | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 192, in __call__ | await response(scope, wrapped_receive, send) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/responses.py", line 257, in __call__ | async with anyio.create_task_group() as task_group: | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 678, in __aexit__ | raise BaseExceptionGroup( | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 412, in run_asgi | result = await app( # type: ignore[func-returns-value] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__ | return await self.app(scope, receive, send) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__ | await super().__call__(scope, receive, send) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__ | await self.middleware_stack(scope, receive, send) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__ | raise exc | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__ | await self.app(scope, receive, _send) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 189, in __call__ | with collapse_excgroups(): | File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 158, in __exit__ | self.gen.throw(value) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 93, in collapse_excgroups | raise exc | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/responses.py", line 260, in wrap | await func() | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 217, in stream_response | return await super().stream_response(send) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/responses.py", line 254, in stream_response | await send({"type": "http.response.body", "body": b"", "more_body": False}) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 161, in _send | await send(message) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 516, in send | output = self.conn.send(event=h11.EndOfMessage()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_connection.py", line 512, in send | data_list = self.send_with_data_passthrough(event) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_connection.py", line 545, in send_with_data_passthrough | writer(event, data_list.append) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_writers.py", line 67, in __call__ | self.send_eom(event.headers, write) | File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_writers.py", line 96, in send_eom | raise LocalProtocolError("Too little data for declared Content-Length") | h11._util.LocalProtocolError: Too little data for declared Content-Length +------------------------------------ During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 412, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__ return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__ await super().__call__(scope, receive, send) File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__ await self.middleware_stack(scope, receive, send) File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__ raise exc File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 158, in __exit__ self.gen.throw(value) File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/responses.py", line 260, in wrap await func() File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/responses.py", line 254, in stream_response await send({"type": "http.response.body", "body": b"", "more_body": False}) File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 161, in _send await send(message) File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 516, in send output = self.conn.send(event=h11.EndOfMessage()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_connection.py", line 512, in send data_list = self.send_with_data_passthrough(event) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_connection.py", line 545, in send_with_data_passthrough writer(event, data_list.append) File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_writers.py", line 67, in __call__ self.send_eom(event.headers, write) File "/Users/isaac/repos/deplio/backend/api/.venv/lib/python3.12/site-packages/h11/_writers.py", line 96, in send_eom raise LocalProtocolError("Too little data for declared Content-Length") h11._util.LocalProtocolError: Too little data for declared Content-Length ```

To Reproduce

Raise a HTTPException with a status code 500.

Expected behavior

No crash.

Operating system macOS 15

zmievsa commented 4 months ago

Oh. I have seen this error in the past. I was sure I fixed it. I'll take a look

isaacharrisholt commented 4 months ago

You're a machine, thanks for fixing!