Skip to content

fix(rest,client): hook 报错 toast 去掉英文调试噪音,只显示业务消息#2893

Merged
os-zhuang merged 1 commit into
mainfrom
claude/hook-error-message-format-fa9b0f
Jul 14, 2026
Merged

fix(rest,client): hook 报错 toast 去掉英文调试噪音,只显示业务消息#2893
os-zhuang merged 1 commit into
mainfrom
claude/hook-error-message-format-fa9b0f

Conversation

@baozhoutao

@baozhoutao baozhoutao commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Closes #2894

问题

控制台里删除被引用记录时,hook 抛出的业务错误在 toast 里显示成:

[ObjectStack] hook 'pm_ref_base' threw: Error: 制作基地被「项目主计划批次」引用(3 条),删除被阻断,请先解除引用

用户不关心错误来自哪个 hook——throw new Error('…') 是作者刻意表达的业务规则,toast 应该只显示业务消息本身。

修复后

制作基地被「项目主计划批次」引用(3 条),删除被阻断,请先解除引用

改动(两处)

  1. @objectstack/rest mapDataError:解包 SandboxError.innerMessage(QuickJS 沙箱在 .message 上带 hook 'x' threw: 调试包装、在 .innerMessage 上保留原始业务消息);实例跨边界丢失时用正则兜底剥离包装。与 http-dispatcher 里自定义 action 路由已有的解包逻辑对齐。
    • 保留 TypeError:非默认错误名——那是真实脚本 bug 的信号,不是业务规则。
    • 新分支刻意不返回 code 字段:旧版打包在控制台里的 @objectstack/client 会把 code 拼进人类可读消息([ObjectStack] CODE: …),会把刚去掉的英文噪音加回来。
  2. @objectstack/client _fetch:error.message 不再拼 [ObjectStack] CODE: 前缀,直接用服务端的人类可读消息;code/category/httpStatus/retryable/details 仍挂在 error 对象上供程序读取。已确认仓库内(含 vendored console dist)没有任何代码对 [ObjectStack] 前缀做字符串匹配。

完整调试包装(hook 名 + 堆栈)仍写入服务端日志(BodyRunner 的 error log + REST 的 unhandled-error log),排障能力不受影响。

测试

  • dogfood 全链路金测试(新增 hook-error-format.dogfood.test.ts):真实内核 + QuickJS 沙箱 hook + 真实 REST,断言 ① DELETE 被沙箱 hook 阻断时 HTTP body 只含业务消息(无 threw:/hook '/[ObjectStack]/code);② 记录确实未被删除;③ TypeError: boom 名字保留。3/3 通过,且服务端日志确认仍输出完整调试包装。
  • @objectstack/rest 单测 +4(innerMessage 解包 / 正则兜底 / TypeError 保名 / action 包装),255 passed。
  • @objectstack/client 单测 +2(message 原样、code 仍可编程读取 / 空 body 回退 statusText),111 passed。

传播说明

已部署控制台要等 objectui 重建其打包的 @objectstack/client 并且 framework 重新 vendor console 后,客户端侧前缀移除才生效;但服务端 REST 侧的解包对旧客户端立即生效(旧客户端只会显示服务端给的干净消息,因为新分支不返回 code)。

@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jul 14, 2026 5:07am

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling size/m labels Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/client, @objectstack/dogfood, @objectstack/rest.

17 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/ai/skills-reference.mdx (via packages/client)
  • content/docs/api/client-sdk.mdx (via @objectstack/client)
  • content/docs/api/data-flow.mdx (via @objectstack/client)
  • content/docs/api/environment-routing.mdx (via @objectstack/client)
  • content/docs/api/error-catalog.mdx (via @objectstack/client, @objectstack/rest)
  • content/docs/api/error-handling-server.mdx (via @objectstack/rest)
  • content/docs/api/index.mdx (via @objectstack/rest)
  • content/docs/kernel/runtime-services/data-service.mdx (via packages/client)
  • content/docs/kernel/runtime-services/index.mdx (via packages/client)
  • content/docs/permissions/authentication.mdx (via @objectstack/client)
  • content/docs/permissions/authorization.mdx (via packages/dogfood, packages/rest)
  • content/docs/permissions/delegated-administration.mdx (via packages/dogfood)
  • content/docs/plugins/index.mdx (via @objectstack/rest)
  • content/docs/plugins/packages.mdx (via @objectstack/client, @objectstack/rest)
  • content/docs/protocol/objectos/realtime-protocol.mdx (via @objectstack/client)
  • content/docs/releases/implementation-status.mdx (via @objectstack/client, @objectstack/rest)
  • content/docs/releases/v12.mdx (via @objectstack/rest)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

@os-zhuang os-zhuang merged commit e46169c into main Jul 14, 2026
17 checks passed
@os-zhuang os-zhuang deleted the claude/hook-error-message-format-fa9b0f branch July 14, 2026 05:24
…ction errors

End users saw the sandbox debug wrapper and client branding in the console
error toast: `[ObjectStack] hook 'pm_ref_base' threw: Error: 制作基地被…`.
A hook's `throw new Error('…')` is a deliberate business rule — the toast
must show only the author's message.

- rest: mapDataError now unwraps SandboxError.innerMessage (and falls back
  to regex-stripping the `hook 'x' threw:` wrapper if the instance was
  lost), keeping non-default names like `TypeError:` as script-bug context.
  No `code` field on these branches — older bundled clients prepend it to
  the human message.
- client: error.message is the server's human-readable message verbatim —
  no `[ObjectStack] CODE:` prefix; code/category/httpStatus stay on the
  error object programmatically.
- dogfood: end-to-end golden test booting a real stack with a sandboxed
  QuickJS hook, asserting the REST body carries only the business message
  while the full debug wrapper still reaches server logs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hook 业务报错在控制台 toast 显示英文调试噪音([ObjectStack] hook 'x' threw: Error: …)

2 participants