Skip to content

fix(role): answer when the customize command has no description - #3296

Merged
zhayujie merged 1 commit into
zhayujie:masterfrom
Lesereingrape:fix/role-empty-customize-argument
Sep 29, 2026
Merged

zhayujie merged 1 commit into
zhayujie:masterfrom
Lesereingrape:fix/role-empty-customize-argument

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

What does this PR do?

$设定扮演 sent without a role description reads that missing description straight
from clist[1] (plugins/role/role.py:207). Nothing on the way out handles the
IndexError: PluginManager.emit_event calls the handler directly
(plugins/plugin_manager.py:293), _generate_reply doesn't wrap it
(channel/chat_channel.py:223-229), and the callback for a failed worker only logs it
(channel/chat_channel.py:452-453). So the user's command gets no reply at all, while
the two sibling commands answer this same mistake right away — $角色 with no name
returns the help text (plugins/role/role.py:185-189) and $角色类型 with no tag asks
for one (plugins/role/role.py:156, answered at :173-174).

The guard copies that existing behaviour instead of inventing new output: an empty
description is answered with the plugin's own help text before clist[1] is touched.

Two pre-existing F541 violations in the same file (f"未知角色类型。\n",
f"请输入角色类型。\n") lose their f prefix here as well. The CI lint job runs ruff's
F class over every Python file a PR changes, so without that the run would fail on
lines this change has nothing to do with.

Fixes #3294

How was this tested?

  • New tests/test_role_empty_customize_argument.py, 3 cases: the bare command now
    replies with the help text, $设定扮演 一位海盗船长 still sets the role, and the $角色
    guard being copied keeps its own reply so the two cannot drift apart.
  • Before the fix the first case fails on a clean ebf206bf worktree with
    IndexError: list index out of range at plugins/role/role.py:207 (1 failed,
    2 passed); with the guard all 3 pass.
  • Full suite: pytest tests/ -q gives 36 failed / 2231 passed / 37 skipped on this
    branch against 36 failed / 2228 passed / 37 skipped on plain ebf206bf, and the two
    failing sets are byte-for-byte identical (diff of the sorted FAILED lines is
    empty) — no new failure, the three extra passes are the new tests.
  • The CI lint gate itself, ruff check plugins/role/role.py tests/test_role_empty_customize_argument.py --select F --ignore F403,F405, passes.

`$设定扮演` on its own reads the missing description straight from
`clist[1]`, so the IndexError leaves `on_handle_context` untouched by
`PluginManager.emit_event` and only reaches the worker's exception
callback, which logs it. The user gets no reply, while the sibling
commands answer the same mistake with their help text.

The two `f` prefixes removed on the role-type branch are pre-existing
F541 violations: the CI lint job runs ruff's F class over every Python
file a PR changes, so they have to go for this file to pass the gate.
@zhayujie
zhayujie merged commit 6798c4a into zhayujie:master Sep 29, 2026
3 checks passed
@zhayujie

Copy link
Copy Markdown
Owner

Merged, thanks! An empty description now gets the help text, not a silent IndexError.

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.

[Bug] $设定扮演 with no role description dies in the handler and the user gets no reply

2 participants