Skip to content

fix(channel): 当没有可用密钥时返回错误而不是第一个密钥 - #2188

Merged
seefs001 merged 1 commit into
mainfrom
fix-multikey-autodisable
Nov 7, 2025
Merged

seefs001 merged 1 commit into
mainfrom
fix-multikey-autodisable

Conversation

@creamlike1024

@creamlike1024 creamlike1024 commented Nov 7, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling in the multi-key polling mechanism to properly detect and report when no enabled keys are available, enabling appropriate system response instead of defaulting to an invalid fallback.

@coderabbitai

coderabbitai Bot commented Nov 7, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The GetNextEnabledKey function in model/channel.go now returns an explicit error when no enabled keys are available, instead of defaulting to the first key. This changes the error signaling behavior for the multi-key polling path, requiring callers to handle this error condition.

Changes

Cohort / File(s) Summary
Error handling update in multi-key polling
model/channel.go
Modified GetNextEnabledKey to return an explicit error when no enabled keys are present, replacing the previous fallback behavior that returned keys[0]

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Specific areas requiring attention:
    • Verify all callers of GetNextEnabledKey properly handle the new error return value
    • Confirm the error is appropriately propagated (e.g., for channel disabling logic)
    • Check for any tests covering the no-enabled-keys scenario

Possibly related PRs

Poem

🐰 Keys once fell back to the first with care,
Now when all are locked, we know it's there—
An error clear, no silent default way,
The channel speaks truth, come what may! 🔑✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and specifically describes the main change: returning an error instead of the first key when no enabled keys are available in GetNextEnabledKey.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-multikey-autodisable

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3dc4d6c and e87b460.

📒 Files selected for processing (1)
  • model/channel.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
model/channel.go (1)
types/error.go (2)
  • NewError (204-224)
  • ErrorCodeChannelNoAvailableKey (52-52)
🔇 Additional comments (1)
model/channel.go (1)

141-146: Improved error handling – verified.

The change correctly returns an explicit error when no enabled keys are available. Verification confirms the only caller at middleware/distributor.go:317 properly handles this error by checking the return value and propagating it upstream:

key, index, newAPIError := channel.GetNextEnabledKey()
if newAPIError != nil {
    return newAPIError
}

No breaking changes to address—the caller already implements the required error handling.


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 and usage tips.

@seefs001
seefs001 merged commit 43ee7a9 into main Nov 7, 2025
@Calcium-Ion
Calcium-Ion deleted the fix-multikey-autodisable branch January 29, 2026 17:10
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…odisable

fix(channel): 当没有可用密钥时返回错误而不是第一个密钥
@coderabbitai coderabbitai Bot mentioned this pull request May 21, 2026
8 of 11 tasks
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…odisable

fix(channel): 当没有可用密钥时返回错误而不是第一个密钥
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…odisable

fix(channel): 当没有可用密钥时返回错误而不是第一个密钥
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