Skip to content

fix(streaming): remove unreachable error check in thread event handler#3111

Open
armorbreak001 wants to merge 1 commit intoopenai:mainfrom
armorbreak001:fix/streaming-dead-code-error-check
Open

fix(streaming): remove unreachable error check in thread event handler#3111
armorbreak001 wants to merge 1 commit intoopenai:mainfrom
armorbreak001:fix/streaming-dead-code-error-check

Conversation

@armorbreak001
Copy link
Copy Markdown

Summary

Fixes #2796

In both Stream.__stream__ and AsyncStream.__stream__, the error handling block inside the thread. event branch contains the condition sse.event == "error". Since this check is nested inside if sse.event.startswith("thread."), and the string "error" never starts with "thread.", this condition is always False — making the entire error-handling block dead code.

This appears to be a regression from a prior refactoring (mentioned in the issue as commit abc25966) where the error check was incorrectly moved inside the thread. branch.

Changes

  • Remove the unreachable sse.event == "error" and predicate from the error condition in both sync and async stream handlers
  • Thread events that carry error payloads in their data will now correctly raise APIError
  • The non-thread error path in the else branch is unchanged

The condition  inside the  event
branch is always False since "error" never starts with "thread.".
This makes the error-handling block dead code.

Remove the redundant predicate so that thread events carrying
error payloads are properly caught and raised as APIError.
@armorbreak001 armorbreak001 requested a review from a team as a code owner April 22, 2026 12:47
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