Skip to content

Conversation

@advent259141
Copy link
Member

@advent259141 advent259141 commented Dec 26, 2025

修复了使用provider指令时索引越界报错不正常的问题

Modifications / 改动点

在使用provider指令切换提供商时,若参数提供的索引越界了,则会报错
在调用插件 builtin_commands 的处理函数 provider 时出现异常:list index out of range
源码中有处理该报错的代码,但并未生效,经检查是少写了return,故加上.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

image image

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

修复提供商选择命令,使其在处理超出范围的索引时不会抛出错误。

错误修复:

  • 在选择 TTS、STT 或通用提供商时,通过在访问前验证索引并在输入无效时提前返回,防止索引超出范围异常。

增强功能:

  • 当提供的提供商索引无效时,改进面向用户的错误消息。
Original summary in English

Summary by Sourcery

Fix provider selection command to correctly handle out-of-range indices without raising errors.

Bug Fixes:

  • Prevent index out-of-range exceptions when selecting TTS, STT, or general providers by validating indices before access and returning early on invalid input.

Enhancements:

  • Improve user-facing error message when an invalid provider index is supplied.

@auto-assign auto-assign bot requested review from Fridemn and Soulter December 26, 2025 07:27
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些总体反馈:

  • 在每个分支中,当你用 get_all_*_providers() 来校验索引(idx2/idx)时,建议先将 provider 列表存到一个本地变量中,然后在长度检查和后续索引时都复用该变量,这样可以避免重复调用,并减少在多次调用间 provider 列表发生变化而导致竞态条件的风险。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- In each branch where you validate the index (`idx2`/`idx`) against `get_all_*_providers()`, consider storing the provider list in a local variable and reusing it for both the length check and the subsequent indexing to avoid redundant calls and potential race conditions if the provider list changes between calls.

Sourcery 对开源项目是免费的——如果你觉得我们的代码评审有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • In each branch where you validate the index (idx2/idx) against get_all_*_providers(), consider storing the provider list in a local variable and reusing it for both the length check and the subsequent indexing to avoid redundant calls and potential race conditions if the provider list changes between calls.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In each branch where you validate the index (`idx2`/`idx`) against `get_all_*_providers()`, consider storing the provider list in a local variable and reusing it for both the length check and the subsequent indexing to avoid redundant calls and potential race conditions if the provider list changes between calls.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 26, 2025
@Soulter Soulter merged commit 703e208 into AstrBotDevs:master Dec 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants