fix(rest,client): hook 报错 toast 去掉英文调试噪音,只显示业务消息#2893
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 3 package(s): 17 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
…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.
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 #2894
问题
控制台里删除被引用记录时,hook 抛出的业务错误在 toast 里显示成:
用户不关心错误来自哪个 hook——
throw new Error('…')是作者刻意表达的业务规则,toast 应该只显示业务消息本身。修复后
改动(两处)
@objectstack/restmapDataError:解包SandboxError.innerMessage(QuickJS 沙箱在.message上带hook 'x' threw:调试包装、在.innerMessage上保留原始业务消息);实例跨边界丢失时用正则兜底剥离包装。与 http-dispatcher 里自定义 action 路由已有的解包逻辑对齐。TypeError:等非默认错误名——那是真实脚本 bug 的信号,不是业务规则。code字段:旧版打包在控制台里的@objectstack/client会把code拼进人类可读消息([ObjectStack] CODE: …),会把刚去掉的英文噪音加回来。@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),排障能力不受影响。
测试
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)。