Repository navigation
ui: 设置→评估页 10 处错误提示显示 IPC 原始英文 message,而按 code 出本地化文案的 errors.* 机制全仓无人调用 - #297
Merged
helsome merged 1 commit intoOct 18, 2026
Merged
Conversation
…e map
The settings -> evaluation page surfaced IPC failures by printing the raw
`error.message` a channel returned. Those messages are English-only strings
produced in the main process, so a zh-CN user got a localized dialog title
followed by an untranslated detail line, e.g.
无法保存更改
STORAGE_WRITE_FAILED: connection is locked
The repo already ships the intended mechanism for this: every failure that
crosses the IPC boundary carries a SCREAMING_SNAKE `code`, and
`packages/i18n/src/error-messages.ts` maps roughly a third of those codes
onto the `errors.*` namespace, which is translated in both locales. The
resolver (`translateErrorCode`) and its table existed but had no production
caller anywhere in the tree, so the localized copy was unreachable.
This wires the page up to it:
- add a small `errorCopy(t, error, fallbackKey)` helper that resolves the
code first, falls back to the raw message, and only then to the existing
per-action key, so unregistered codes keep their previous text exactly;
- replace the 10 `result?.error.message ?? t(...)` sites with it.
The helper needs the real `TFunction` (options are not expressible through
the previous narrowed signature), so the import is widened to the i18next
type rather than a local function shape.
Both new cases fail before this change and pass after:
- a registered code renders `errors.*` copy instead of the raw message,
- an unregistered code still renders its raw message (the fallback contract).
Verification (local; upstream CI is disabled_manually, so no check runs are
produced for this PR):
- `bun test packages/ui --isolate` -> 344 pass / 0 fail (63 files)
- `bunx tsc --noEmit` -> exit 0
- `bun run i18n:check` -> key parity en-US 1487 = zh-CN 1487, 0 issues
Closes helsome#296
helsome
approved these changes
Oct 18, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
独立代码审查及本轮精确 HEAD 验证通过,focused 7 pass / 0 fail。按本批顺序累计树完整测试 1856 pass / 7 skip / 0 fail,全 workspace typecheck、i18n 通过,新增变更 secret 扫描无命中。仅接受本 PR 声明范围,不将离线回归/SSR 视为完整桌面或真实模型验收。
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.
问题与修复
Closes #296
设置 → 评估页的 10 处失败提示都写成「优先用 IPC 信封里的原始
message」,而error.message通常都存在,?? t(...)那一侧几乎永远不生效 —— 本地化文案被架空。界面语言 zh-CN、evaluation.getSettings返回{ ok:false, error:{ code:'STORAGE_WRITE_FAILED', message:'STORAGE_WRITE_FAILED: connection is locked' } }时,用户看到的是本地化标题 + 一行未翻译的英文,且把内部 code 一起暴露:仓库其实已经为「按稳定 code 出本地化文案」建好了完整机制:
packages/i18n/src/locales/{en-US,zh-CN}/errors.ts(34 条用户可见文案)+packages/i18n/src/error-messages.ts的ERROR_CODE_TO_KEY(33 条 code → key 静态表)/errorKeyForCode/translateErrorCode。但全仓检索后,这三个符号的引用只有三处、全部在机制自己内部(定义、它自己的单测packages/i18n/src/i18n.test.ts、barrelpackages/i18n/src/index.ts),没有任何生产代码调用 —— 这条设计路径从表到解析器齐备,却没接上任何一个渲染面。修复:加一个 4 行 helper,把解析顺序定成「注册过的 code → 本地化文案;未注册的 code → 保留 sanitized message;两者都没有 → 页面原有的
settings.evaluation.*兜底键」,10 处调用点改为调它。3a17eca6)EvaluationSettingsTab.tsx:1-6import type { TFunction } from 'i18next';、translateErrorCode自@finagent/i18n,并把ApiError加入原有的@finagent/core类型 import:36-38errorCopyhelper:90:118:137:161:181:194:207:228:251:265result?.error.message ?? t('<原键>')→errorCopy(t, result?.error, '<原键>')不删除未注册 code 的原始 message(那是有用的诊断信息),只是不再让它抢占已注册 code 的本地化文案。
errorCopy需要真实TFunction(可选项无法通过收窄签名表达),因此这里的类型用 i18next 的公开类型而非本地函数形状。零新增 i18n 键:
errors.*与settings.evaluation.*都已存在,bun run i18n:check的en-US 1487 ≡ zh-CN 1487不变。可复现测试报告
环境:Windows
10.0.26200.9457(x64)、Bun1.4.2、main3a17eca6。在既有
packages/ui/src/components/evaluation/evaluation.test.tsx追加 2 个用例(用client.prefs.get把界面语言钉成 zh-CN,再把evaluation.getSettings桩成失败):errors.*本地化文案」;修复前:该文件 6 pass / 1 fail,唯一失败即上文的
Expected "无法保存更改"/Received "STORAGE_WRITE_FAILED: connection is locked"。另一个新用例本来就通过 —— 这正是「保留原始 message」这一半契约已经正确、缺的只是「已注册 code 没被解析」的直接证据。修复后:该文件 7 pass / 0 fail。
工作区回归:
bun test packages/ui --isolatebun x tsc --noEmitbun run i18n:checkkey parity: en-US 1487 keys ≡ zh-CN 1487 keys (0 issues)上游
PR checks(.github/workflows/pr.yml)当前state=disabled_manually,新建 PR 不会产生 check run,故以上均为本地等价命令结果,非 CI 结论。范围
result.error.message(ModelsTab.tsx、AgentPanel.tsx、EvaluationCenter.tsx、CaseDetail.tsx、ExperimentDetail.tsx、EventsView.tsx、AppShell.tsx等),属同一更大的范围,未并入本 PR;本 PR 先用一页把机制接通并留下可复制的判据。CODE_KIND_TABLE漏了ACCESS_DENIED;本条是 i18n 侧「code → 用户可见文案」的解析器没有调用方。:39附近的日期本地化(formatDate),本条改的是:90之后的 10 处错误文案,两处相距 50 行、无重叠上下文,可独立合并。