Extract symbolicateStackTrace into its own module

Summary:
Having a function that symbolicates any given stack trace
is convenient, e.g. in #7459

More cleanup to follow.

Reviewed By: davidaurelio

Differential Revision: D3348616

fbshipit-source-id: 6313ec837869c6080829c811345a06aa1b2dcd21
This commit is contained in:
Alex Kotliarskyi
2016-06-01 13:50:34 -07:00
committed by Facebook Github Bot 2
parent 7e100ac7a2
commit 2ef533352f
3 changed files with 47 additions and 54 deletions

View File

@@ -7,31 +7,19 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule parseErrorStack
* @flow
*/
'use strict';
export type StackFrame = {
file: string;
lineNumber: number;
column: number;
};
var stacktraceParser = require('stacktrace-parser');
function resolveSourceMaps(sourceMapInstance, stackFrame) {
try {
var orig = sourceMapInstance.originalPositionFor({
line: stackFrame.lineNumber,
column: stackFrame.column,
});
if (orig) {
// remove query string if any
const queryStringStartIndex = orig.source.indexOf('?');
stackFrame.file = queryStringStartIndex === -1
? orig.source
: orig.source.substring(0, queryStringStartIndex);
stackFrame.lineNumber = orig.line;
stackFrame.column = orig.column;
}
} catch (innerEx) {
}
}
function parseErrorStack(e, sourceMaps) {
function parseErrorStack(e: Error): Array<StackFrame> {
if (!e || !e.stack) {
return [];
}
@@ -43,19 +31,6 @@ function parseErrorStack(e, sourceMaps) {
stack.shift();
}
if (sourceMaps) {
sourceMaps.forEach((sourceMap, index) => {
stack.forEach(frame => {
if (frame.file.indexOf(sourceMap.file) !== -1 ||
frame.file.replace('.map', '.bundle').indexOf(
sourceMap.file
) !== -1) {
resolveSourceMaps(sourceMap, frame);
}
});
});
}
return stack;
}