diff --git a/IntegrationTests/GlobalEvalWithSourceUrlTest.js b/IntegrationTests/GlobalEvalWithSourceUrlTest.js index 52fbe0e2fa8..a30bfeec12d 100644 --- a/IntegrationTests/GlobalEvalWithSourceUrlTest.js +++ b/IntegrationTests/GlobalEvalWithSourceUrlTest.js @@ -59,7 +59,7 @@ class GlobalEvalWithSourceUrlTest extends React.Component<{...}> { 'Expected globalEvalWithSourceUrl to throw an Error object', ); } - const parsedStack = parseErrorStack(error); + const parsedStack = parseErrorStack(error?.stack); if (parsedStack[0].file !== url) { throw new Error( `Expected first eval stack frame to be in ${url} but found ${String( diff --git a/Libraries/Core/Devtools/__tests__/parseErrorStack-test.js b/Libraries/Core/Devtools/__tests__/parseErrorStack-test.js index c361f7a9edc..a92172c9876 100644 --- a/Libraries/Core/Devtools/__tests__/parseErrorStack-test.js +++ b/Libraries/Core/Devtools/__tests__/parseErrorStack-test.js @@ -18,7 +18,7 @@ function getFakeError() { describe('parseErrorStack', function() { it('parses error stack', function() { - const stack = parseErrorStack(getFakeError()); + const stack = parseErrorStack(getFakeError().stack); expect(stack.length).toBeGreaterThan(0); const firstFrame = stack[0]; @@ -33,12 +33,12 @@ describe('parseErrorStack', function() { return error; } - const stack = parseErrorStack(getWrappedError()); + const stack = parseErrorStack(getWrappedError().stack); expect(stack[0].methodName).toEqual('getFakeError'); }); it('ignores bad inputs', function() { - expect(parseErrorStack({})).toEqual([]); + expect(parseErrorStack(undefined)).toEqual([]); expect(parseErrorStack(null)).toEqual([]); }); }); diff --git a/Libraries/Core/Devtools/parseErrorStack.js b/Libraries/Core/Devtools/parseErrorStack.js index 3df85895ab7..fe2cc205375 100644 --- a/Libraries/Core/Devtools/parseErrorStack.js +++ b/Libraries/Core/Devtools/parseErrorStack.js @@ -47,22 +47,22 @@ function convertHermesStack(stack: HermesParsedStack): Array { return frames; } -function parseErrorStack(e: ExtendedError): Array { - if (!e || !e.stack) { +function parseErrorStack(errorStack?: string): Array { + if (errorStack == null) { return []; } const stacktraceParser = require('stacktrace-parser'); - const stack = Array.isArray(e.stack) - ? e.stack + const parsedStack = Array.isArray(errorStack) + ? errorStack : global.HermesInternal - ? convertHermesStack(parseHermesStack(e.stack)) - : stacktraceParser.parse(e.stack).map(frame => ({ + ? convertHermesStack(parseHermesStack(errorStack)) + : stacktraceParser.parse(errorStack).map(frame => ({ ...frame, column: frame.column != null ? frame.column - 1 : null, })); - return stack; + return parsedStack; } module.exports = parseErrorStack; diff --git a/Libraries/Core/ExceptionsManager.js b/Libraries/Core/ExceptionsManager.js index ba35831eeb8..6da6d8a4a30 100644 --- a/Libraries/Core/ExceptionsManager.js +++ b/Libraries/Core/ExceptionsManager.js @@ -59,7 +59,7 @@ function reportException( const NativeExceptionsManager = require('./NativeExceptionsManager').default; if (NativeExceptionsManager) { const parseErrorStack = require('./Devtools/parseErrorStack'); - const stack = parseErrorStack(e); + const stack = parseErrorStack(e?.stack); const currentExceptionID = ++exceptionID; const originalMessage = e.message || ''; let message = originalMessage; diff --git a/Libraries/LogBox/Data/LogBoxData.js b/Libraries/LogBox/Data/LogBoxData.js index 9d35132a490..b9890449b4c 100644 --- a/Libraries/LogBox/Data/LogBoxData.js +++ b/Libraries/LogBox/Data/LogBoxData.js @@ -198,8 +198,7 @@ export function addLog(log: LogData): void { // otherwise spammy logs would pause rendering. setImmediate(() => { try { - // TODO: Use Error.captureStackTrace on Hermes - const stack = parseErrorStack(errorForStackTrace); + const stack = parseErrorStack(errorForStackTrace?.stack); appendNewLog( new LogBoxLog({