Skip to content

fix: show error when submitting multi-document yaml - #354

Open
MrWindlike wants to merge 1 commit into
0.4.x-devfrom
fix/yaml-multi-document-error
Open

fix: show error when submitting multi-document yaml#354
MrWindlike wants to merge 1 commit into
0.4.x-devfrom
fix/yaml-multi-document-error

Conversation

@MrWindlike

Copy link
Copy Markdown
Collaborator

问题

在 YAML 编辑器中填写多个 --- 分隔的文档后点击提交,界面没有任何反应:弹窗不关闭、不报错、按钮也不进入 loading 状态。

根因

useYamlFormonFinish 中,validateRules 的调用在 try之外

monaco-yaml 的 Kubernetes 模式允许多文档 YAML,因此 isYamlValid / isSchemaValid 均为 true,校验放行;随后 validateRules 内部用 js-yaml 的单文档 yaml.load() 解析,抛出 expected a single document in the stream, but found more。该异常逃出 onFinish,被 YamlForm.tsx 的空 catch {} 静默吞掉。

catch 块里其实已经写好了针对这个错误的处理,会提示 dovetail.only_support_one_yaml(「一次仅支持输入一个 YAML 配置。」),只是覆盖不到 validateRules 这次调用。

改动

  • validateRules 的调用移入既有的 try 块,让已有的错误处理生效
  • catch 中补 setRulesErrors([])validateRules 抛错时不会写入 rulesErrors,需清空避免上次提交的规则错误残留,与上方 YAML 语法错误分支的处理保持对称
  • 新增 __tests__/hooks/useYamlForm.spec.ts,覆盖多文档提交给出提示并中止、单文档提交正常走通两条路径

测试

  • 新增用例通过,且回退修复后多文档用例确实失败,确认测试能捕获该 bug
  • 全量单测 29 passed(原 27 + 新增 2)
  • pnpm lint 0 error
  • pnpm build(vite + tsc)通过

validateRules was called outside the try block, so the single-document
error thrown by js-yaml escaped to YamlForm's empty catch and the submit
button appeared to do nothing.
@webzard-io-agent-review

Copy link
Copy Markdown

@webzard-io-agent-review

Copy link
Copy Markdown

LGTM,本轮审查未发现需要修改的问题。

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