From 1001cf653cfb43c68000994f2e9f8cd9976c912c Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 22 Jun 2023 09:13:25 -0700 Subject: [PATCH] Pass native stack to ExceptionManager (#37995) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37995 We now have native stack symbols (since D45182122) for TurboModule exceptions, so report those to ExceptionManager so they can end up in the crash reporting pipeline. It will likely not get symbolicated properly yet, but at least we'll have some metadata. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D46893131 fbshipit-source-id: 2b2713ed3af9a366cc43f8ceaef36000834310c7 --- .../Libraries/Core/ExceptionsManager.js | 20 +++++++++++++------ .../Libraries/Core/ExtendedError.js | 12 +++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/react-native/Libraries/Core/ExceptionsManager.js b/packages/react-native/Libraries/Core/ExceptionsManager.js index d1de23cfa02..78252549622 100644 --- a/packages/react-native/Libraries/Core/ExceptionsManager.js +++ b/packages/react-native/Libraries/Core/ExceptionsManager.js @@ -78,6 +78,19 @@ function reportException( message = e.jsEngine == null ? message : `${message}, js engine: ${e.jsEngine}`; + // $FlowFixMe[unclear-type] + const extraData: Object = { + // $FlowFixMe[incompatible-use] we can't define a type with a Symbol-keyed field in flow + ...e[decoratedExtraDataKey], + jsEngine: e.jsEngine, + rawStack: e.stack, + }; + if (e.cause != null && typeof e.cause === 'object') { + extraData.stackSymbols = e.cause.stackSymbols; + extraData.stackReturnAddresses = e.cause.stackReturnAddresses; + extraData.stackElements = e.cause.stackElements; + } + const data = preprocessException({ message, originalMessage: message === originalMessage ? null : originalMessage, @@ -87,12 +100,7 @@ function reportException( stack, id: currentExceptionID, isFatal, - extraData: { - // $FlowFixMe[incompatible-use] we can't define a type with a Symbol-keyed field in flow - ...e[decoratedExtraDataKey], - jsEngine: e.jsEngine, - rawStack: e.stack, - }, + extraData, }); if (reportToConsole) { diff --git a/packages/react-native/Libraries/Core/ExtendedError.js b/packages/react-native/Libraries/Core/ExtendedError.js index 2ff43c88a9c..7ce700eb119 100644 --- a/packages/react-native/Libraries/Core/ExtendedError.js +++ b/packages/react-native/Libraries/Core/ExtendedError.js @@ -18,4 +18,16 @@ export type ExtendedError = Error & // Note: A field keyed by the Symbol ExceptionsManager.decoratedExtraDataKey is also read from ExtendedErrors. // This field isn't documented in the types as Flow does not support this usecase, but it's effectively: // [decoratedExtraDataKey]?: {[string]: mixed}, + + // Included for native errors + cause?: { + name: string, + message: string, + // $FlowFixMe[unclear-type] + stackElements?: $ReadOnlyArray, + // $FlowFixMe[unclear-type] + stackSymbols?: $ReadOnlyArray, + // $FlowFixMe[unclear-type] + stackReturnAddresses?: $ReadOnlyArray, + }, };