Repository navigation
0.2.22 规则正则匹配对无效正则容错,告警跳过而非中断整条回复链 - #40
Merged
Merged
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's Guide本次更新将版本升级至 0.2.22(37),并在正则规则匹配处捕获无效表达式异常、记录告警后跳过该规则,从而保证后续回复规则仍能继续执行。 Sequence diagram for invalid regex rule handlingsequenceDiagram
participant Event as PluginEvent
participant Runtime as reply_runtime
participant Regex as re.match
participant Logger as Proc.log
Event->>Runtime: reply_runtime(plugin_event, Proc)
Runtime->>Regex: re.match(pattern, tmp_message)
alt Invalid regular expression
Regex-->>Runtime: re.error
Runtime->>Logger: Proc.log(1, warning)
Runtime-->>Runtime: continue to next rule
else Valid regular expression
Regex-->>Runtime: match result
Runtime-->>Runtime: Continue normal reply processing
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="ChanceCustom/replyCore.py" line_range="305" />
<code_context>
- res_re = re.match('^%s$' % tmp_dictCustomData_this[key_this]['key'], tmp_message)
+ try:
+ res_re = re.match('^%s$' % tmp_dictCustomData_this[key_this]['key'], tmp_message)
+ except re.error as e:
+ Proc.log(
+ 1,
</code_context>
<issue_to_address>
**Regex errors stop reply processing**
When a configured regex is deeply nested enough to raise `RecursionError` or uses a repetition count beyond the regex engine's limit, `re.match` raises `RecursionError` or `OverflowError`, but the handler catches only `re.error`; the exception escapes `reply_runtime` and `unity_reply` instead of skipping the rule, stopping the reply chain.
Catch `RecursionError` and `OverflowError` alongside `re.error` so these patterns are logged and skipped.
Also at `ChanceCustom/replyCore.py:304`.
</issue_to_address>
### Comment 2
<location path="ChanceCustom/replyCore.py" line_range="306-310" />
<code_context>
+ try:
+ res_re = re.match('^%s$' % tmp_dictCustomData_this[key_this]['key'], tmp_message)
+ except re.error as e:
+ Proc.log(
+ 1,
+ 'ChanceCustom 规则[%s]的正则表达式无效,已跳过: %s'
+ % (tmp_dictCustomData_this[key_this]['key'], e)
+ )
+ continue
if res_re is not None:
</code_context>
<issue_to_address>
**Invalid rules flood operator logs**
When an invalid regex rule remains configured while incoming messages continue in a busy chat, `reply_runtime` calls `Proc.log` with the same warning on every evaluation, including evaluations triggered by group and private messages; the repeated warnings overwhelm useful diagnostics and can consume log storage.
Deduplicate or rate-limit the warning per invalid rule instead of logging it on every evaluation.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: ChanceCustom/replyCore.py:305, ChanceCustom/replyCore.py:310
lunzhiPenxil
approved these changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
为自定义回复规则增加无效正则容错,确保异常规则不会阻断后续回复处理。
Bug Fixes:
Chores: