Make OpenAI and Open Responses error enums public - #268
Merged
Merged
Conversation
OpenAILanguageModelError and OpenResponsesLanguageModelError were internal, so callers could see these errors only as any Error and couldn't match their cases. The Core ML, llama.cpp, and MLX error enums are already public. Make both enums and their error descriptions public, and document each case with the conditions that throw it.
A response.failed event carries the failed response with an error code and message, but OpenResponsesLanguageModelError.streamFailed dropped them. OpenAILanguageModel in the Responses variant ignored the event entirely, so a failed stream ended without saying why. Add code and message to streamFailed, include them in its error description, and add the same case to OpenAILanguageModelError, thrown when the Responses variant receives response.failed.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The public API, failure propagation, decoding, documentation, and tests are consistent and complete.
Review effort: Balanced
Findings: None
What changed in this PR
Makes OpenAI provider errors publicly matchable and preserves server failure details during streaming.
Changes:
- Exposes both provider error enums and descriptions.
- Propagates
response.failedcodes and messages. - Adds external-module coverage for error matching and streaming failures.
| File | Description |
|---|---|
OpenAILanguageModel.swift |
Handles failed Responses streams and exposes errors. |
OpenResponsesLanguageModel.swift |
Preserves failure details and exposes errors. |
ResponseStreamFailure.swift |
Decodes and formats streaming failure details. |
ProviderErrorTests.swift |
Tests public matching and failure propagation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenAILanguageModelErrorandOpenResponsesLanguageModelErrorare internal, so a caller who gets one sees onlyany Errorand can't match on its cases. The Core ML, llama.cpp, and MLX error enums are already public. Two stream failures also lose information:OpenResponsesLanguageModelError.streamFaileddrops the error code and message that aresponse.failedevent carries, andOpenAILanguageModelwith the.responsesvariant ignoresresponse.failedentirely, so the stream ends without an error.This PR makes both enums and their
errorDescriptionpublic, and documents when each case is thrown.streamFailedbecomesstreamFailed(code: String?, message: String?), with the values from the failed response'serrorobject, and its description includes them.OpenAILanguageModelErrorgets the samestreamFailed(code:message:)case, which the.responsesvariant now throws when it receivesresponse.failed.noResponseGeneratedis unchanged on both.This isn't purely additive.
streamFailednow has associated values,OpenAILanguageModelErrorhas a new case, and a streamedOpenAILanguageModelresponse that fails on the server now throws instead of ending quietly. Code outside the package couldn't name these types before, so no existingswitchorcatchbreaks. Because 1.0 freezes these cases, now is the time to change them.