normalize() throws when a getter throws a Symbol or a null-prototype object

未关闭 适合新手
#25,920 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@rjmcgee53192 已经在做这个了。

开始于 2026年10月30日。

  • #25967 来自 @rjmcgee53192 —— 未关闭

评估

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

调研方向

阅读 packages/core/src/utils/normalize.ts,重点查看 normalize 和 stringifyValue 中的 catch 块。使用 issue 中的三个 getter 示例重现问题,并检查被捕获的值为 Symbol 或无原型对象时,是否仍会作为异常逸出。完成标准是所有情况都返回一个不可序列化标记,且不抛出异常。

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

描述

Is there an existing issue for this?
How do you use Sentry?

Not applicable. The reproduction calls normalize from @sentry/core directly, without a DSN.

Which SDK are you using?

@sentry/core (the normalize utility that every SDK uses)

SDK Version

11.10.0

Steps to Reproduce

Node.js 24.21.0:

const { normalize } = require('@sentry/core')

const throwsError = { get x() { throw new Error('getter failed') } }
const throwsSymbol = { get x() { throw Symbol('s') } }
const throwsNullProto = { get x() { throw Object.create(null) } }

normalize({ bad: throwsError }, 3)
normalize({ bad: throwsSymbol }, 3)
normalize({ bad: throwsNullProto }, 3)
Expected Result

normalize returns the **non-serializable** marker for all three, as its JSDoc states: "returns A normalized version of the object, or "**non-serializable**" if any errors are thrown during normalization."

Actual Result
{ ERROR: '**non-serializable** (Error: getter failed)' }
TypeError: Cannot convert a Symbol value to a string
TypeError: Cannot convert object to primitive value

The second and third calls throw out of normalize.

Additional Context

Both catch blocks in packages/core/src/utils/normalize.ts (in normalize and in stringifyValue) build the marker with a template literal, `**non-serializable** (${err})`. The template literal converts the caught value to a string. That conversion throws for a Symbol and for an object without a usable toString or Symbol.toPrimitive. The current develop branch has the same code. A conversion that cannot throw, with a fixed fallback text, would keep normalize total.

主要语言
TypeScript
星标
8.8k
派生
1.9k
平均合并
1 天 19 小时
30 天内合并 PR
664

环境准备

从这里开始

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

getsentry/sentry-javascript 的其他 Issue

查看 getsentry/sentry-javascript 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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