Skip to content

Make OpenAI and Open Responses error enums public - #268

Merged
mattt merged 2 commits into
mainfrom
mattt/public-provider-errors
Sep 25, 2026
Merged

mattt merged 2 commits into
mainfrom
mattt/public-provider-errors

Conversation

@mattt

@mattt mattt commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

OpenAILanguageModelError and OpenResponsesLanguageModelError are internal, so a caller who gets one sees only any Error and 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.streamFailed drops the error code and message that a response.failed event carries, and OpenAILanguageModel with the .responses variant ignores response.failed entirely, so the stream ends without an error.

This PR makes both enums and their errorDescription public, and documents when each case is thrown. streamFailed becomes streamFailed(code: String?, message: String?), with the values from the failed response's error object, and its description includes them. OpenAILanguageModelError gets the same streamFailed(code:message:) case, which the .responses variant now throws when it receives response.failed. noResponseGenerated is unchanged on both.

This isn't purely additive. streamFailed now has associated values, OpenAILanguageModelError has a new case, and a streamed OpenAILanguageModel response that fails on the server now throws instead of ending quietly. Code outside the package couldn't name these types before, so no existing switch or catch breaks. Because 1.0 freezes these cases, now is the time to change them.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.failed codes 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.

@mattt
mattt merged commit eefd76f into main Sep 25, 2026
13 checks passed
@mattt
mattt deleted the mattt/public-provider-errors branch September 25, 2026 13:54
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