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

Đang mở Phù hợp với người mới
#798 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với src/db/errors.ts tại unwrapDatabaseError và tái hiện cause có prototype null được nêu trong issue. Đảm bảo việc đọc DatabaseError.message giữ lại một thông báo hữu ích thay vì gây lỗi, sau đó kiểm tra độ bao phủ trong các bài kiểm thử lỗi hiện có. Issue cũng nêu một hướng điều tra riêng về prototype của cause trong đường đi fiber-failure.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
5
Fork
4
Merge trung bình
9 giờ 44 phút
Pull request đã merge (30 ngày)
217

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NEARBuilders/everything-dev

Tất cả issue của NEARBuilders/everything-dev

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.