Skip to content

fix: 当 PR 对应的 Issue 不存在时跳过处理而非崩溃#475

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-error-when-issue-does-not-exist
Open

fix: 当 PR 对应的 Issue 不存在时跳过处理而非崩溃#475
Copilot wants to merge 2 commits intomainfrom
copilot/fix-error-when-issue-does-not-exist

Conversation

Copy link

Copilot AI commented Mar 18, 2026

在解决冲突 PR 时,若对应议题已被删除(GitHub API 返回 404),to_issue_handler 会抛出未捕获的 ActionFailed,导致整个 bot 进程崩溃,后续 PR 均无法处理。

Changes

  • publish/utils.py & remove/utils.py: 在 resolve_conflict_pull_requests 中,对 to_issue_handler 调用添加 try/except (ActionFailed, RequestFailed),捕获 404 后记录错误并 continue 至下一个 PR

    try:
        issue_handler = await handler.to_issue_handler(issue_number)
    except (ActionFailed, RequestFailed):
        logger.error(f"议题 #{issue_number} 不存在,跳过处理 {pull.title}")
        continue

    同时捕获 RequestFailed:生产环境中 adapter 将 githubkit 的 RequestFailed 包装为 ActionFailed,测试框架(nonebug)则直接抛出 RequestFailed

  • test_resolve_pull_request.py: 新增 test_resolve_pull_request_issue_not_found,验证议题 404 时对应 PR 被跳过、后续 PR 仍正常处理。

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • releases.astral.sh
    • Triggering command: /home/REDACTED/.local/bin/uv uv sync (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>bug: 当 PR 对应的 Issue 不存在时会报错</issue_title>
<issue_description>https://github.com/nonebot/nonebot2/actions/runs/23191121358/job/67387193264?pr=3887#step:5:125

03-17 19:05:16 [INFO] github:publish | 正在处理 Plugin: CS2 Bridge
03-17 19:05:16 [INFO] nonebot | Matcher(type='', module=src.plugins.github.plugins.resolve, lineno=57) running complete
03-17 19:05:16 [ERROR] nonebot | Running Matcher(type='', module=src.plugins.github.plugins.resolve, lineno=57) failed.
Traceback (most recent call last):
  File "/app/bot.py", line 100, in <module>
    nonebot.run()
  File "/app/.venv/lib/python3.13/site-packages/nonebot/__init__.py", line 337, in run
    get_driver().run(*args, **kwargs)
  File "/app/.venv/lib/python3.13/site-packages/nonebot/drivers/none.py", line 61, in run
    anyio.run(self._serve)
  File "/app/.venv/lib/python3.13/site-packages/anyio/_core/_eventloop.py", line 74, in run
    return async_backend.run(func, args, {}, backend_options)
  File "/app/.venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2284, in run
    return runner.run(wrapper())
  File "/usr/local/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 712, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 683, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2042, in _run_once
    handle._run()
  File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
  File "/app/.venv/lib/python3.13/site-packages/nonebot/utils.py", line 254, in run_coro_with_shield
    return await coro
  File "/app/.venv/lib/python3.13/site-packages/nonebot/message.py", line 506, in check_and_run_matcher
    await _run_matcher(
> File "/app/.venv/lib/python3.13/site-packages/nonebot/message.py", line 458, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "/app/.venv/lib/python3.13/site-packages/nonebot/internal/matcher/matcher.py", line 926, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "/app/.venv/lib/python3.13/site-packages/nonebot/internal/matcher/matcher.py", line 863, in simple_run
    await handler(
  File "/app/.venv/lib/python3.13/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "/app/src/plugins/github/plugins/resolve/__init__.py", line 86, in handle_pr_close
    await resolve_conflict_pull_requests(handler, pull_requests)
  File "/app/src/plugins/github/plugins/resolve/__init__.py", line 39, in resolve_conflict_pull_requests
    await resolve_conflict_publish_pull_requests(handler, [pull_request])
  File "/app/src/plugins/github/plugins/publish/utils.py", line 135, in resolve_conflict_pull_requests
    issue_handler = await handler.to_issue_handler(issue_number)
  File "/app/src/plugins/github/handlers/github.py", line 29, in to_issue_handler
    issue = await self.get_issue(issue_number)
  File "/app/src/plugins/github/handlers/github.py", line 259, in get_issue
    await self.bot.rest.issues.async_get(
  File "/app/.venv/lib/python3.13/site-packages/nonebot/adapters/github/utils.py", line 33, in __call__
    return await self.bot.call_api(".".join(self.parts), **kwargs)
  File "/app/.venv/lib/python3.13/site-packages/nonebot/internal/adapter/bot.py", line 176, in call_api
    raise exception
  File "/app/.venv/lib/python3.13/site-packages/nonebot/internal/adapter/bot.py", line 128, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "/app/.venv/lib/python3.13/site-packages/nonebot/adapters/github/adapter.py", line 122, in _call_api
    raise ActionFailed(e.response) from None
nonebot.adapters.github.exception.ActionFailed: ActionFailed(method=GET, url=https://api.github.com/repos/nonebot/nonebot2/issues/3890, status_code=404 Not Found)
03-17 19:05:16 [INFO] nonebot | Shutting down
03-17 19:05:16 [INFO] nonebot | Waiting for application shutdown. (CTRL+C to force quit)
03-17 19:05:16 [INFO] nonebot | Application shutdown complete.
```</issue_description>

<agent_instructions>如果遇到对应的 issue 不存在时,应该跳过这个  PR,继续处理接下来的。</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix error when PR corresponds to non-existent issue fix: 当 PR 对应的 Issue 不存在时跳过处理而非崩溃 Mar 18, 2026
Copilot AI requested a review from he0119 March 18, 2026 12:08
@he0119 he0119 marked this pull request as ready for review March 18, 2026 12:10
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.96%. Comparing base (da9ce20) to head (3e10b81).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/plugins/github/plugins/remove/utils.py 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #475      +/-   ##
==========================================
- Coverage   96.07%   95.96%   -0.12%     
==========================================
  Files          40       40              
  Lines        2320     2330      +10     
==========================================
+ Hits         2229     2236       +7     
- Misses         91       94       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 当 PR 对应的 Issue 不存在时会报错

2 participants