Skip to content

fix: 命令与表单错误处理 - #2

Merged
XiaoYangx666 merged 3 commits into
devfrom
agent/fix-command-form-stability
Jul 31, 2026
Merged

fix: 命令与表单错误处理#2
XiaoYangx666 merged 3 commits into
devfrom
agent/fix-command-form-stability

Conversation

@XiaoYangx666

@XiaoYangx666 XiaoYangx666 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

摘要

  • 未知命令反馈改为合法的 RawMessage 对象,避免 ScriptAPI 原生类型转换失败。
  • 规范化带引号的字符串参数(去除外层引号),并支持小数坐标。
  • 构建命令树时保持调用方持有的参数定义不可变(深度克隆)。
  • 忽略 show() 中预期的 FormRejectError 拒绝,同时让表单 builder/handler 的真实错误继续抛出。
  • InputForm 兼容 label/divider 等展示字段:保留全部字段与 formValues 槽位对齐,解析循环跳过非值字段。

根本原因

未知命令路径向 Player.sendMessage 传入了原始数组,而 ScriptAPI 期望的是字符串或 RawMessage
对象;玩家在响应前离开导致的表单拒绝错误也会变成未处理的 Promise 拒绝。

验证

  • npx tsgo -p tsconfig.build.json --noEmit
  • npx tsgo -p tsconfig.json --noEmit
  • npx vitest run(98 个测试全部通过)

XiaoYangx666 and others added 3 commits July 21, 2026 15:39
基岩版 1.21+ 中 label/divider 会占据 formValues 槽位(值为 undefined),
而 InputForm 原先生成字段时只保留值字段做长度校验,导致使用 LabelField
时 values.length !== fields.length,提交报字段长度不匹配并重开表单。

改为保留全部字段与 formValues 槽位对齐,解析循环跳过非值字段。

Co-Authored-By: Claude <noreply@anthropic.com>
覆盖:保留全部字段与 formValues 槽位对齐、解析循环跳过展示字段、
必填校验按槽位定位、长度不匹配拦截、取消路径。修复 39cd087 无测试覆盖的遗留风险。

Co-Authored-By: Claude <noreply@anthropic.com>
@XiaoYangx666 XiaoYangx666 changed the title Fix command and form error handling fix: 命令与表单错误处理 Jul 31, 2026
@XiaoYangx666
XiaoYangx666 marked this pull request as ready for review July 31, 2026 09:47
@XiaoYangx666
XiaoYangx666 merged commit 34b8729 into dev Jul 31, 2026
1 check passed
@XiaoYangx666
XiaoYangx666 deleted the agent/fix-command-form-stability branch July 31, 2026 09:50
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.

1 participant