From af670c83196fd2cdf56ed5892f207d005c5f24e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Wed, 23 Jul 2025 04:41:42 -0700 Subject: [PATCH] Honor ignored frames in errors reported by Fantom (#52765) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52765 Changelog: [internal] Reported locations for errors in Fantom is wrong, because it seems it's not ignoring "infra" frames. This was caused by the `stack` property in `ErrorWithCustomBlame` being set on the error objects and shadowing the getter that removes the necessary frames. This fixes that by forcing that property to be deleted. Reviewed By: christophpurrer Differential Revision: D78747119 fbshipit-source-id: 81d6ce74041382d7582e2066409e839d28d91052 --- private/react-native-fantom/runtime/expect.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/private/react-native-fantom/runtime/expect.js b/private/react-native-fantom/runtime/expect.js index 6d876ed59c3..5a465afa96d 100644 --- a/private/react-native-fantom/runtime/expect.js +++ b/private/react-native-fantom/runtime/expect.js @@ -24,6 +24,15 @@ class ErrorWithCustomBlame extends Error { #cachedProcessedStack: ?string; #customStack: ?string; + constructor(message?: string, options?: {cause?: mixed, ...}) { + super(message, options); + + // The Error constructor forces an own `stack` property that shadows our + // getter, so deleting it restores that behavior. + // $FlowExpectedError[incompatible-type] + delete this.stack; + } + blameToPreviousFrame(): this { this.#cachedProcessedStack = null; this.#ignoredFrameCount++; @@ -34,6 +43,10 @@ class ErrorWithCustomBlame extends Error { get stack(): string { if (this.#cachedProcessedStack == null) { const originalStack = this.#customStack ?? super.stack; + // Calling `super.stack` forces an own `stack` property that shadows our + // getter, so deleting it restores that behavior. + // $FlowExpectedError[incompatible-type] + delete this.stack; const lines = originalStack.split('\n'); const index = lines.findIndex(line =>