Skip to content

Commit 8601f50

Browse files
committed
Updates
1 parent 075a7b7 commit 8601f50

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/a2a/utils/error_handlers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ async def error_catching_iterator() -> AsyncGenerator[
175175
yield item
176176
except Exception as stream_error: # noqa: BLE001
177177
_log_error(stream_error)
178+
raise stream_error
178179

179180
response.body_iterator = error_catching_iterator()
180181

tests/utils/test_error_handlers.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def successful_func():
125125

126126
@pytest.mark.asyncio
127127
async def test_rest_stream_error_handler_generator_error(caplog):
128-
"""Test rest_stream_error_handler logs error during async generation and ends stream gracefully."""
128+
"""Test rest_stream_error_handler catches error during async generation after first success."""
129129
error = InternalError(message='Stream error during generation')
130130

131131
async def failing_generator():
@@ -141,18 +141,21 @@ async def successful_prep_failing_stream():
141141
# Assert it returns successfully
142142
assert isinstance(response, MockEventSourceResponse)
143143

144-
# Consume the stream - error should be logged but not re-raised
144+
# Now consume the stream
145145
chunks = []
146-
with caplog.at_level(logging.ERROR):
146+
with (
147+
caplog.at_level(logging.ERROR),
148+
pytest.raises(InternalError) as exc_info,
149+
):
147150
async for chunk in response.body_iterator:
148151
chunks.append(chunk) # noqa: PERF401
149152
assert chunks == ['success chunk 1']
150-
assert 'Stream error during generation' in caplog.text
153+
assert exc_info.value == error
151154

152155

153156
@pytest.mark.asyncio
154157
async def test_rest_stream_error_handler_generator_unknown_error(caplog):
155-
"""Test rest_stream_error_handler logs unknown error during async generation and ends stream gracefully."""
158+
"""Test rest_stream_error_handler catches unknown error during async generation."""
156159

157160
async def failing_generator():
158161
yield 'success chunk 1'
@@ -164,9 +167,11 @@ async def successful_prep_failing_stream():
164167

165168
response = await successful_prep_failing_stream()
166169

167-
# Consume the stream - error should be logged but not re-raised
168170
chunks = []
169-
with caplog.at_level(logging.ERROR):
171+
with (
172+
caplog.at_level(logging.ERROR),
173+
pytest.raises(RuntimeError, match='Unknown stream failure'),
174+
):
170175
async for chunk in response.body_iterator:
171176
chunks.append(chunk) # noqa: PERF401
172177
assert chunks == ['success chunk 1']

0 commit comments

Comments
 (0)