fix(linkai): reply when the midjourney image index is not a number by Lesereingrape · Pull Request #3291 · zhayujie/CowAgent · GitHub
Skip to content

fix(linkai): reply when the midjourney image index is not a number - #3291

Merged
zhayujie merged 1 commit into
zhayujie:masterfrom
Lesereingrape:fix/midjourney-index-argument
Sep 29, 2026
Merged

zhayujie merged 1 commit into
zhayujie:masterfrom
Lesereingrape:fix/midjourney-index-argument

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

What does this PR do?

$mju / $mjv parse the image index with a bare int() (plugins/linkai/midjourney.py:161). The two mistakes around that argument the code already anticipates -- one missing (命令缺少参数, line 158) and a number outside 1..4 (图片序号 N 错误, line 163) -- both answer the user, but a token that is not a number at all raises ValueError out of process_mj_task. It escapes on_handle_context into ChatChannel._fail_callback (channel/chat_channel.py:452-453), which only logs:

logger.exception("Worker return exception: {}".format(exception))

So $mju 11055927171882 2x produces no message of any kind -- not an error, not a hint about the expected shape. Copying an index out of a UI or typing 2x is an ordinary slip.

This PR guards the parse and replies through the same _set_reply_text path the neighbouring guards use, so the failure is visible to the user:

try:
    index = int(clist[1])
except ValueError:
    self._set_reply_text(f"图片序号 {clist[1]} 错误,应为 1 至 4 的数字", e_context)
    return

The three f prefixes removed elsewhere in the file carry no placeholders. The lint job runs ruff check --select F over the files a PR touches, so that inherited F-class debt in the same file would otherwise turn this PR's gate red.

Type of change

  • Bug fix
  • New feature
  • Refactor / chore

Tests

tests/test_linkai_midjourney_index_argument.py drives process_mj_task(TaskType.UPSCALE, ...) through an EventContext, the way the existing tests/test_linkai_midjourney_send.py and tests/test_keyword_attachment_urls.py do, and asserts both that a non-numeric token now gets a reply and that the existing 1..4 message still fires for 9.

  • Before the fix, on plain c7ae3ba5: 1 failed, 1 passed -- ValueError: invalid literal for int() with base 10: '2x' at plugins/linkai/midjourney.py:161.
  • After the fix: 2 passed.
  • pytest tests/ -q: 38 failed, 2216 passed on this branch vs 38 failed, 2214 passed on plain c7ae3ba5 -- same failures, +2 from the new file.
  • ruff check plugins/linkai/midjourney.py tests/test_linkai_midjourney_index_argument.py --select F --ignore F403,F405: All checks passed.

Checklist

$mju/$mjv parse the image index with a bare int(), so a token like "2x"
raises ValueError out of on_handle_context. The worker's callback only
logs it, so the command produces no reply at all, while the two
neighbouring mistakes on the same argument (missing, or numeric but
outside 1..4) both answer.

Also drop three f-strings without placeholders in the touched file: the
lint job scans only files a PR changes, so inherited F-class debt turns
that gate red.
@zhayujie
zhayujie merged commit 5da52c8 into zhayujie:master Sep 29, 2026
3 checks passed
@zhayujie

Copy link
Copy Markdown
Owner

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.

C:/Users/20235/.qoder/bin/git/$mjv with a non-numeric image index raises ValueError and the user gets no reply

2 participants