fix: preserve Error details in event properties - #4803
Open
marandaneto wants to merge 1 commit into
Open
Conversation
marandaneto
requested review from
a team,
ablaszkiewicz,
cat-ph and
hpouillot
September 5, 2026 17:22
marandaneto
marked this pull request as ready for review
September 5, 2026 17:23
Contributor
Prompt To Fix All With AI### Issue 1
packages/browser-common/src/utils/request-utils.ts:16
**Cross-realm Errors lose details**
An `Error` created in another browser realm, such as an iframe, fails the `instanceof Error` check. The serializer then treats it as an ordinary object and drops its non-enumerable `name`, `message`, and `stack`, so the issue this change intends to fix remains for cross-realm errors. Please use the existing cross-realm-safe `isError` predicate for this check.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "fix: preserve Error details in event pro..." | Re-trigger Greptile |
| data, | ||
| (_, value) => { | ||
| // Native JSON.stringify invokes toJSON before this replacer, so custom serializers win. | ||
| if (value instanceof Error) { |
Contributor
There was a problem hiding this comment.
Cross-realm Errors lose details
An Error created in another browser realm, such as an iframe, fails the instanceof Error check. The serializer then treats it as an ordinary object and drops its non-enumerable name, message, and stack, so the issue this change intends to fix remains for cross-realm errors. Please use the existing cross-realm-safe isError predicate for this check.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browser-common/src/utils/request-utils.ts
Line: 16
Comment:
**Cross-realm Errors lose details**
An `Error` created in another browser realm, such as an iframe, fails the `instanceof Error` check. The serializer then treats it as an ordinary object and drops its non-enumerable `name`, `message`, and `stack`, so the issue this change intends to fix remains for cross-realm errors. Please use the existing cross-realm-safe `isError` predicate for this check.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Contributor
Contributor
|
Size Change: +3.83 kB (+0.02%) Total Size: 20.4 MB 📦 View Changed
ℹ️ View Unchanged
|
Contributor
posthog-js Compliance ReportDate: 2026-09-05 17:30:40 UTC ✅ All Tests Passed!26/26 tests passed Capture Tests✅ 26/26 tests passed View Details
|
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.
Problem
Error values in event properties lose their name, message, and stack during JSON serialization. This also affects additional properties passed to
captureException.Related to #1977. Date values and custom
toJSONmethods already work on the current base.Changes
Include Error details and enumerable custom fields without mutating the original Error. Skip unreadable non-enumerable details so a throwing getter does not discard the request batch. Reuse Error copies so circular references still reach the existing fallback.
Keep native Date and custom
toJSONbehavior, BigInt conversion, andbefore_sendtiming unchanged. Add utility, exception-property, and request-batch regression tests.Validation
298852763ebcb4db80490f3cec1c8026447e7ca4with no findings.dompurifyanddotenv. Clean-base equivalence was not verified. No dependency or configuration workaround was added.Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset fileThe existing patch changeset is included. No duplicate changeset was created during publication.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Pi implemented the fix and ran tests using shell tools, Git, pnpm, and GitHub CLI. Independent source review identified an unreadable-getter regression, which was reproduced and fixed before publication. Pi autoreview checked the final committed branch. The local session has no shareable URL.
The change stays in browser-common request serialization rather than changing exception capture timing or the shared core fallback. Human review is required.