Commit eed80a7
fix: use get_final_message() to prevent AttributeError on early stream termination
Fixes #1868
When the Anthropic API stream terminates before sending message_stop
(e.g. network timeout, connection reset), the last event in the
async for loop may not have a .message attribute, causing:
AttributeError: 'TextEvent' object has no attribute 'message'
Replace the fragile event.message.usage access with
stream.get_final_message() which safely returns the accumulated
message snapshot regardless of how the stream ended. Falls back to
the old pattern for test/mock streams that lack this API.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent fca208b commit eed80a7
1 file changed
+9
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
413 | 421 | | |
414 | 422 | | |
415 | 423 | | |
| |||
0 commit comments