Skip to content

Fix unreachable error handling code in streaming#2849

Open
veeceey wants to merge 1 commit intoopenai:mainfrom
veeceey:fix/issue-2796-dead-code-streaming
Open

Fix unreachable error handling code in streaming#2849
veeceey wants to merge 1 commit intoopenai:mainfrom
veeceey:fix/issue-2796-dead-code-streaming

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 7, 2026

Summary

  • Fixed unreachable error check in Stream and AsyncStream classes
  • The condition sse.event == "error" could never be true inside a block that requires sse.event.startswith("thread.")
  • Changed to check for sse.event == "thread.error" which is the correct event name for thread error events

Changes

  • Updated error event check in Stream.__stream__() (line 67)
  • Updated error event check in AsyncStream.__stream__() (line 170)
  • Added test case for thread.error events to verify they raise APIError
  • Added test case for non-error thread events to ensure they still process correctly

Test Results

All tests pass:

$ pytest tests/test_streaming.py -v
======================== 24 passed in 0.04s ========================

Specifically:

  • test_thread_error_event[sync] - Verifies thread.error raises APIError
  • test_thread_error_event[async] - Verifies thread.error raises APIError (async)
  • test_thread_non_error_event[sync] - Verifies other thread.* events work
  • test_thread_non_error_event[async] - Verifies other thread.* events work (async)

Fixes #2796

Fixed unreachable error check in Stream and AsyncStream classes where
`sse.event == "error"` could never be true inside a block that requires
`sse.event.startswith("thread.")`. Changed condition to check for
`sse.event == "thread.error"` which is the correct event name.

Added test cases to verify thread.error events are properly caught and
raise APIError, and that non-error thread events continue to process
correctly.

Fixes openai#2796
@veeceey veeceey requested a review from a team as a code owner February 7, 2026 23:31
@veeceey
Copy link
Author

veeceey commented Feb 8, 2026

Ready for review and merge. All tests passing.

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.

Bug: Dead code - sse.event == "error" check is unreachable in _streaming.py

1 participant