mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
60b4ba16c0
Summary: Fixes a bug where we were skewing some stack traces by sending 1-based column numbers to the Metro symbolication endpoint, which expects them to be 0-based. This is achieved by subtracting 1 from the column numbers we find in textual stack traces, which are almost universally 1-based in current JS engines. The bug is only noticeable in *some* cases, namely where the column immediately following the correct one is in a different function. NOTE: The behaviour under Hermes was fixed separately, in a previous commit. This fix applies to other engines (e.g. JSC). Changelog: [General] [Fixed] - Fix stack traces showing the wrong function name in some cases Reviewed By: cpojer Differential Revision: D18628230 fbshipit-source-id: 5677803500e45a41c1005496d19c150526af2d07
69 lines
1.6 KiB
JavaScript
69 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {StackFrame} from '../NativeExceptionsManager';
|
|
import type {HermesParsedStack} from './parseHermesStack';
|
|
|
|
const parseHermesStack = require('./parseHermesStack');
|
|
|
|
export type ExtendedError = Error & {
|
|
jsEngine?: string,
|
|
preventSymbolication?: boolean,
|
|
componentStack?: string,
|
|
forceRedbox?: boolean,
|
|
isComponentError?: boolean,
|
|
...
|
|
};
|
|
|
|
function convertHermesStack(stack: HermesParsedStack): Array<StackFrame> {
|
|
const frames = [];
|
|
for (const entry of stack.entries) {
|
|
if (entry.type !== 'FRAME') {
|
|
continue;
|
|
}
|
|
const {location, functionName} = entry;
|
|
if (location.type === 'NATIVE') {
|
|
continue;
|
|
}
|
|
frames.push({
|
|
methodName: functionName,
|
|
file: location.sourceUrl,
|
|
lineNumber: location.line1Based,
|
|
column:
|
|
location.type === 'SOURCE'
|
|
? location.column1Based - 1
|
|
: location.virtualOffset0Based,
|
|
});
|
|
}
|
|
return frames;
|
|
}
|
|
|
|
function parseErrorStack(e: ExtendedError): Array<StackFrame> {
|
|
if (!e || !e.stack) {
|
|
return [];
|
|
}
|
|
|
|
const stacktraceParser = require('stacktrace-parser');
|
|
const stack = Array.isArray(e.stack)
|
|
? e.stack
|
|
: global.HermesInternal
|
|
? convertHermesStack(parseHermesStack(e.stack))
|
|
: stacktraceParser.parse(e.stack).map(frame => ({
|
|
...frame,
|
|
column: frame.column != null ? frame.column - 1 : null,
|
|
}));
|
|
|
|
return stack;
|
|
}
|
|
|
|
module.exports = parseErrorStack;
|