fix: show error when submitting multi-document yaml - #354
Open
MrWindlike wants to merge 1 commit into
Open
Conversation
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.
|
LGTM,本轮审查未发现需要修改的问题。 |
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.
问题
在 YAML 编辑器中填写多个
---分隔的文档后点击提交,界面没有任何反应:弹窗不关闭、不报错、按钮也不进入 loading 状态。根因
useYamlForm的onFinish中,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块,让已有的错误处理生效setRulesErrors([]):validateRules抛错时不会写入 rulesErrors,需清空避免上次提交的规则错误残留,与上方 YAML 语法错误分支的处理保持对称__tests__/hooks/useYamlForm.spec.ts,覆盖多文档提交给出提示并中止、单文档提交正常走通两条路径测试
pnpm lint0 errorpnpm build(vite + tsc)通过