Skip to content

refactor: remove deprecated openai-error-handler shim and use error-handler#767

Open
daewoongoh wants to merge 4 commits into
Zoo-Code-Org:mainfrom
daewoongoh:refactor/remove-deprecated-openai-error-handler
Open

refactor: remove deprecated openai-error-handler shim and use error-handler#767
daewoongoh wants to merge 4 commits into
Zoo-Code-Org:mainfrom
daewoongoh:refactor/remove-deprecated-openai-error-handler

Conversation

@daewoongoh

@daewoongoh daewoongoh commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #766

Description

This PR removes the deprecated openai-error-handler compatibility shim and consolidates all related imports to use the canonical error-handler utility directly.

error-handler has been the canonical source for OpenAI-compatible error handling since RooCodeInc/Roo-Code#10204. The deprecated openai-error-handler module only acted as a shim, so keeping it added unnecessary duplication and maintenance overhead.

Key changes:

  • Replaced all imports of the deprecated openai-error-handler shim with error-handler.
  • Removed src/api/providers/utils/openai-error-handler.ts.
  • Removed the duplicate openai-error-handler.spec.ts test file.
  • Kept the actual OpenAI-compatible error handling behavior centralized in error-handler.ts.
  • Continued relying on error-handler.spec.ts, which already covers the same behavior previously tested by the removed duplicate test.

This PR is intended to be a no-behavior-change refactor. It simplifies the provider utility structure while preserving the existing handleOpenAIError behavior.

Test Procedure

pnpm check-types
pnpm test

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A

Documentation Updates

  • No documentation updates are required.

Get in Touch

hehegwk_23849

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency of error messages across multiple AI provider and code index embedder flows by routing failures through a shared error handler (including proper provider-prefixed formatting and status preservation).
    • Removed reliance on the deprecated OpenAI-specific error handler so behavior is normalized across OpenAI-compatible services.
  • Tests
    • Added a DeepSeek streaming failure test to verify the wrapped error message prefix and preserved status.
  • Chores
    • Removed the obsolete OpenAI error handler unit test coverage.

… error-handler

Replace all imports of the deprecated `openai-error-handler` shim with
`error-handler`, which has been the canonical source since #10204.
Delete `openai-error-handler.ts` and its duplicate test file, as
`error-handler.spec.ts` already covers the same behavior.

Signed-off-by: daewoongoh <dw.oh@samsung.com>
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b401e09b-4895-4342-9bbd-fd05f6157606

📥 Commits

Reviewing files that changed from the base of the PR and between a11eba3 and 3951724.

📒 Files selected for processing (2)
  • src/api/providers/__tests__/deepseek.spec.ts
  • src/api/providers/deepseek.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/api/providers/tests/deepseek.spec.ts
  • src/api/providers/deepseek.ts

📝 Walkthrough

Walkthrough

Removes the deprecated openai-error-handler shim module and its test file. All handleOpenAIError imports across providers and embedders now point to error-handler directly.

Changes

Shim removal and import consolidation

Layer / File(s) Summary
Import paths switched
src/api/providers/base-openai-compatible-provider.ts, src/api/providers/openai.ts, src/api/providers/openrouter.ts, src/api/providers/requesty.ts, src/api/providers/unbound.ts, src/api/providers/lm-studio.ts, src/api/providers/deepseek.ts, src/api/providers/xai.ts, src/api/providers/zai.ts, src/services/code-index/embedders/openai-compatible.ts, src/services/code-index/embedders/openai.ts, src/services/code-index/embedders/openrouter.ts
Provider and embedder files import handleOpenAIError from error-handler instead of openai-error-handler, while their existing error-handling call sites remain unchanged.
Shim and test removed
src/api/providers/utils/openai-error-handler.ts, src/api/providers/utils/__tests__/openai-error-handler.spec.ts
The deprecated openai-error-handler module and its dedicated spec file are deleted.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related PRs

  • Zoo-Code-Org/Zoo-Code#6: Touches DeepSeek provider and tests, including DeepSeekHandler.createMessage, which is one of the files updated to import handleOpenAIError from error-handler.

Suggested labels: awaiting-review

Suggested reviewers: taltas, hannesrudolph, navedmerchant, JamesRobert20, edelauna

Poem

🐇 Hop hop, the shim is gone,
One path where two paths led before.
error-handler stands alone,
No deprecated detour more.
The warren's tidy, clean, and bright! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: removing the deprecated shim and switching to the canonical error handler.
Description check ✅ Passed The description matches the required template and includes the issue link, change summary, testing steps, checklist, and notes.
Linked Issues check ✅ Passed The PR fulfills #766 by replacing shim imports, deleting the deprecated file and duplicate test, and preserving behavior.
Out of Scope Changes check ✅ Passed The added DeepSeek test and import path updates are directly related to the shim removal and canonical handler consolidation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Cover the catch block that wraps API errors via handleOpenAIError,
fixing 0% patch coverage on the error path.

Signed-off-by: daewoongoh <dw.oh@samsung.com>
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jun 30, 2026
@daewoongoh daewoongoh changed the title refactor: remove deprecated openai-error-handler and consolidate into… refactor: remove deprecated openai-error-handler shim and use error-handler Jun 30, 2026
@daewoongoh

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good - had some comments around test accuracy and import consistency.

Comment thread src/api/providers/deepseek.ts Outdated
)
} catch (error) {
const { handleOpenAIError } = await import("./utils/openai-error-handler")
const { handleOpenAIError } = await import("./utils/error-handler")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Every other provider uses a static import for handleOpenAIError at the top of the file — is there a reason this one uses a dynamic import inside the catch block? If not, a static import would keep it consistent.

Suggested change
const { handleOpenAIError } = await import("./utils/error-handler")
import { handleOpenAIError } from "./utils/error-handler"

(And the catch body becomes just throw handleOpenAIError(error, "DeepSeek"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There wasn’t a specific reason to keep this as a dynamic import.
I’ve updated DeepSeek to use the same static handleOpenAIError import as the other providers and simplified the catch block to call throw handleOpenAIError(error, "DeepSeek") directly.

mockCreate.mockRejectedValueOnce(apiError)

const stream = handler.createMessage(systemPrompt, messages)
await expect(stream.next()).rejects.toThrow("DeepSeek completion error: Invalid API key")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test checks the message format, but .status is what the retry/backoff logic reads downstream — could we assert that it is preserved too?

Suggested change
await expect(stream.next()).rejects.toThrow("DeepSeek completion error: Invalid API key")
const err = await stream.next().catch((e) => e)
expect(err.message).toBe("DeepSeek completion error: Invalid API key")
expect((err as any).status).toBe(401)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’ve updated the DeepSeek error test to capture the thrown error and assert both the wrapped message and the preserved status value.
This should cover the downstream retry/backoff logic that reads .status.

@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 1, 2026
daewoongoh and others added 2 commits July 2, 2026 09:31
…Error

Replace dynamic `await import()` with a static import for `handleOpenAIError`
in the catch block, and update the error handler test to also assert the HTTP
status code (401) on the thrown error.

Signed-off-by: daewoongoh <dw.oh@samsung.com>
@daewoongoh daewoongoh requested a review from edelauna July 2, 2026 01:08
@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review and removed awaiting-author PR is waiting for the author to address requested changes labels Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Remove deprecated openai-error-handler shim

2 participants