Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`void/log` serializes `Error` fields as `{}`, losing message and stack

Đang mở
#577 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á

Issue này chưa được đánh giá.

Mô tả

Summary

logger.error() is meant for surfacing caught errors (#168), but an Error passed as a field is logged as {}. Its message, stack and cause are non-enumerable, so JSON.stringify drops them. Nothing fails, so this goes unnoticed until someone needs the log.

Reproduction

[email protected] (same code on main):

import { logger } from 'void/log';

logger.error('save failed', { error: new Error('boom') });
// {"msg":"save failed","error":{}}

logger.error('save failed', { error: new Error('wrapped', { cause: new Error('inner') }) });
// {"msg":"save failed","error":{}}

class AppError extends Error {
  status = 500;
}
logger.error('save failed', { error: new AppError('boom') });
// {"msg":"save failed","error":{"status":500}}

Expected

The error's details are kept, for example:

{"msg":"save failed","error":{"name":"Error","message":"boom","stack":"Error: boom\n    at ..."}}

Suggested fix

Pass a replacer to the existing JSON.stringify call in format(). This also covers nested errors and cause chains, keeps custom enumerable fields such as status, and leaves the { msg, ...fields } shape unchanged:

function replacer(_key: string, value: unknown) {
  if (value instanceof Error) {
    return { ...value, name: value.name, message: value.message, stack: value.stack, cause: value.cause };
  }
  return value;
}

return JSON.stringify(payload, replacer);

The existing catch fallback still handles circular references.

If passing Error objects is intentionally unsupported, a note in the logger docs to pass error.message / error.stack as strings would help.

Ngôn ngữ chính
TypeScript
Star
580
Fork
56
Merge trung bình
8 giờ 32 phút
Pull request đã merge (30 ngày)
111

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 voidzero-dev/void

Tất cả issue của voidzero-dev/void

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.