Skip to content

fix(streaming): move error event check before thread.* handling#2807

Open
yurekami wants to merge 1 commit intoopenai:mainfrom
yurekami:fix-dead-code-streaming
Open

fix(streaming): move error event check before thread.* handling#2807
yurekami wants to merge 1 commit intoopenai:mainfrom
yurekami:fix-dead-code-streaming

Conversation

@yurekami
Copy link

Summary

Fixes #2796

The sse.event == "error" check inside the sse.event.startswith("thread.") block was unreachable dead code, since a string cannot simultaneously equal "error" and start with "thread.".

Changes

  • Moved error event handling (sse.event == "error") to a separate check before the thread.* event handling
  • Applied fix to both sync (Stream.__stream__) and async (AsyncStream.__stream__) implementations
  • Changed if to elif for the thread.* check to maintain proper control flow

Before

if sse.event and sse.event.startswith("thread."):
    # ...
    if sse.event == "error":  # ❌ Unreachable - never true
        raise APIError(...)

After

if sse.event == "error":  # ✅ Now reachable
    # ...
    raise APIError(...)
elif sse.event and sse.event.startswith("thread."):
    # ...

Test Plan

  • Ruff check passes
  • Existing tests pass

🤖 Generated with Claude Code

The `sse.event == "error"` check was unreachable inside the
`sse.event.startswith("thread.")` block since a string cannot
simultaneously equal "error" and start with "thread.".

This moves error event handling to a separate check before the
thread.* event handling, ensuring error events are properly caught
and raise APIError.

Fixes openai#2796

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@yurekami yurekami requested a review from a team as a code owner December 28, 2025 20:33
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