feat: Add new skill error handling and localization messages#6761
Merged
c121914yu merged 3 commits intolabring:mainfrom Apr 20, 2026
Merged
Conversation
c121914yu
reviewed
Apr 17, 2026
Collaborator
c121914yu
left a comment
There was a problem hiding this comment.
📋 需求理解
本 PR 的目标是将 agent skill 相关 API 的 ad-hoc 错误消息迁移到集中的 SkillErrEnum 并补齐 en/zh-CN/zh-Hant 三语 i18n 翻译;同时把 import.ts 与 save-deploy.ts 从手写 NextApiRequest/jsonRes 形式迁移到统一的 NextAPI(handler) 包装器。
🧪 逻辑验证(测例推理)
我对关键路径做了阅读推理,均通过:
- ✅
Promise.reject(SkillErrEnum.xxx)→NextEntrycatch →processError按字符串查表ERROR_RESPONSE['xxx']→ 命中agentSkillErr注册的 i18n message + code(509003+)。 - ✅ 新增的 11 个枚举 append 到原有 3 个之后,已有错误码(
509000~509002)数值稳定,客户端没有 breaking。 - ✅
import.ts的try/catch/finally控制流:return Promise.reject(...)在 try 里不会触发本地 catch,但finally中multer.clearDiskTempFiles(filepaths)仍然会运行,临时文件清理无泄漏。 - ✅
save-deploy.ts的mongoSessionRun事务内部抛出UserError时,会被外层 NextAPI catch 正确映射为 500 + 可读 message。 ⚠️ import.ts:166err.message?.includes('already exists')依赖下层字符串,健壮性存疑(见行级评论)。
⚠️ 问题汇总
🟡 建议改进
save-deploy.ts:多处具体错误(validateZipStructure 的validation.error、SKILL.md 缺失)被折叠成同一个invalidSkillPackage,调试体验倒退,至少应记录原始 detail。edit.ts:SSE 路径使用new UserError('skillId is required'),而sseErrRes已支持字符串枚举查表。可改成sseErrRes(res, SkillErrEnum.unExist)享受 i18n,与其他 handler 保持一致。import.ts:Archive is empty/Failed to extract archive/超大文件错误仍是英文UserError,本 PR 的 i18n 目标没有覆盖到这里。import.ts:166通过err.message?.includes('already exists')匹配业务错误,脆弱且容易被下层消息改动悄悄打破,建议在importSkill内部直接throw SkillErrEnum.skillNameExists。create.ts:68/71两个语义不同的校验(name 为空 vs name > 50)合并为同一个invalidSkillName。i18n 文案合并成 “empty or over 50 characters” 勉强覆盖,但不如拆成两个枚举值或两个独立 key 更精确。
🟢 可选优化
create.ts:71name.length > 50用的是原始长度而不是name.trim().length,与后续checkSkillNameExists(name.trim(), ...)不一致(pre-existing,非本 PR 引入)。zh-Hant译文存儲在繁体语境下更常用的写法是儲存;欄位正确,其余翻译 OK。- 本次没有配套单测。
SkillErrEnum新增值→i18n key 的闭环、以及import.ts/save-deploy.tsNextAPI 改造后的错误响应结构可以加点 e2e/integration 断言。
✅ 做得好的地方
- 错误码以 append 方式加到
skillErrList末尾,保留了已有错误码的数值稳定性。 import.ts、save-deploy.ts去掉了手写req.method !== 'POST'/jsonRes分支,统一走NextAPI,跟仓库其他路由风格对齐。- 三语 i18n 同步更新,没有漏翻。
🚀 审查结论
需修改:建议至少修复 save-deploy.ts 错误 detail 丢失、import.ts 的 magic string 匹配,并在后续补齐 edit.ts / import.ts 剩余英文字面量的 i18n。非 blocking 的可以跟进 PR。
|
✅ Build Successful - Preview code-sandbox Image for this PR: |
|
✅ Build Successful - Preview fastgpt Image for this PR: |
|
✅ Build Successful - Preview mcp_server Image for this PR: |
20b15ca to
4804478
Compare
c121914yu
previously approved these changes
Apr 17, 2026
c121914yu
approved these changes
Apr 20, 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.
No description provided.