Skip to content

Conversation

samuelreh
Copy link
Contributor

@samuelreh samuelreh commented Sep 4, 2025

Summary

  • Fixes a bug where OpenAI::Errors::APIError.for was being called in stream.rb, but this method doesn't exist
  • Changes it to use OpenAI::Errors::APIStatusError.for which is the correct method that handles error creation

Problem

The APIError class doesn't have a for class method, but APIStatusError does. This was causing a NoMethodError when streaming encounters an error response.

Solution

Updated lib/openai/internal/stream.rb line 41 to call APIStatusError.for instead of APIError.for.

Test plan

  • Verified that APIStatusError class has the for method in lib/openai/errors.rb:149
  • Verified that APIError class does not have a for method
  • Test streaming with error conditions to ensure proper error handling

@samuelreh samuelreh requested a review from a team as a code owner September 4, 2025 20:49
@@ -38,7 +38,7 @@ class Stream
else
"An error occurred during streaming"
end
err = OpenAI::Errors::APIError.for(
err = OpenAI::Errors::APIStatusError.for(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my god I am so sorry, this is such an embarrassing bug 🐛.

🤦‍♀️

Copy link
Collaborator

@ms-jpq ms-jpq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the PR @samuelreh! I will have this fix published in a jiffy.

I don't think I should merge this particular change though, unless we remote the claude code authorship for understandable reasons. 😅

@samuelreh
Copy link
Contributor Author

@ms-jpq All good, feel free to regenerate it with GPT-5 💪

The APIError class doesn't have a 'for' class method, but APIStatusError does.
This fixes a NoMethodError that would occur when streaming encounters an error.

test: add test for streaming error handling with APIStatusError.for

This test verifies that streaming error responses properly use
APIStatusError.for instead of the non-existent APIError.for method.
@samuelreh samuelreh force-pushed the fix-apierror-for-method branch from 93db98b to 666ad67 Compare September 5, 2025 04:05
@samuelreh
Copy link
Contributor Author

@ms-jpq I re-authored the commits and stripped the description of my buddy, feel free to merge if you think the fix is up to snuff.

@ms-jpq ms-jpq changed the base branch from main to next September 5, 2025 05:39
@ms-jpq
Copy link
Collaborator

ms-jpq commented Sep 5, 2025

hey hey @samuelreh , thank you so much!

@ms-jpq ms-jpq merged commit 275e19b into openai:next Sep 5, 2025
@stainless-app stainless-app bot mentioned this pull request Sep 5, 2025
stainless-app bot pushed a commit that referenced this pull request Sep 5, 2025
The APIError class doesn't have a 'for' class method, but APIStatusError does.
This fixes a NoMethodError that would occur when streaming encounters an error.

test: add test for streaming error handling with APIStatusError.for

This test verifies that streaming error responses properly use
APIStatusError.for instead of the non-existent APIError.for method.
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.

2 participants