unwrapDatabaseError masks real DB errors with TypeError: Cannot convert object to primitive value

已关闭 适合新手
#798 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #813 来自 @elliotBraem —— 已合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
backend

调研方向

从 src/db/errors.ts 中的 unwrapDatabaseError 入手,复现 issue 中展示的 null-prototype cause。确保读取 DatabaseError.message 时会保留有用的消息,而不是抛出错误,然后检查现有错误测试的覆盖情况。issue 还指出需要单独调查 fiber-failure 路径中的 cause-prototype。

由索引模型根据 Issue 内容生成。

描述

Version: everything-dev 2.0.0-rc.39

unwrapDatabaseError (src/db/errors.ts:19) does String(error) for any cause that isn't an instanceof Error:

if (!(error instanceof Error)) return String(error);

When the cause is a non-Error object that has no primitive conversion (null-prototype object), String() throws TypeError: Cannot convert object to primitive value — and since this runs inside the DatabaseError.message getter, the TypeError replaces the real error everywhere .message is read (oRPC error serialization, vitest failure rendering, log lines).

Observed in CI: a PGlite failure surfaced as TypeError: Cannot convert object to primitive value with this stack, fully hiding the actual DatabaseError [stage=driver] message:

❯ unwrapDatabaseError everything-dev/src/db/errors.ts:19:40
❯ get message everything-dev/src/db/errors.ts:13:15
❯ get message every-plugin/src/runtime/errors.ts:12:16

Repro (node, using the shipped dist/db/errors.cjs):

const { DatabaseError } = require("everything-dev/db");
const dbErr = new DatabaseError({ stage: "driver", cause: Object.create(null) });
dbErr.message; // TypeError: Cannot convert object to primitive value

Additionally, somewhere between a layer-build failure (Effect.tryPromise passes the thrown Error through intact — verified) and usePlugin's rejection, the DatabaseError's cause is replaced by a null-prototype object, so this path is reachable in practice, not just contrived.

Suggested fix: make unwrapDatabaseError defensive for non-Error causes — try/catch around String(error), or a stringifyUnknown-style fallback (every-plugin's runtime/errors.ts already has one). Sibling fix worth investigating: why the fiber-failure path strips the cause's prototype before it reaches DatabaseError.message.

主要语言
TypeScript
星标
5
派生
4
平均合并
9 小时 52 分钟
30 天内合并 PR
222

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NEARBuilders/everything-dev 的其他 Issue

查看 NEARBuilders/everything-dev 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。