Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion faststream/asgi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def start_lifespan_context(

except ExceptionGroup as e:
for ex in e.exceptions:
raise ex from None
raise ex from ex.__cause__

async def __start(
self,
Expand Down
25 changes: 25 additions & 0 deletions tests/asgi/test_lifespan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from starlette.testclient import TestClient

from faststream.asgi import AsgiFastStream


@pytest.mark.asyncio()
async def test_chained_exception_cause_preserved_on_startup_failure() -> None:
"""AsgiFastStream must not discard __cause__ when re-raising startup exceptions unwrapped from anyio's ExceptionGroup.

This is a regression test for https://github.com/ag2ai/faststream/issues/2780
"""
app = AsgiFastStream()

cause = ConnectionError("underlying cause")

@app.on_startup
async def failing_startup() -> None:
msg = "application startup failed"
raise RuntimeError(msg) from cause

with pytest.raises(RuntimeError) as exc_info, TestClient(app):
pass

assert exc_info.value.__cause__ is cause
Loading