2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2016-06-01 20:50:34 +00:00
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-01 20:50:34 +00:00
|
|
|
export type StackFrame = {
|
2017-02-27 10:33:49 +00:00
|
|
|
column: ?number,
|
2016-08-09 13:32:41 +00:00
|
|
|
file: string,
|
|
|
|
lineNumber: number,
|
2017-02-27 10:33:49 +00:00
|
|
|
methodName: string,
|
2016-06-01 20:50:34 +00:00
|
|
|
};
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2017-06-14 16:16:26 +00:00
|
|
|
export type ExtendedError = Error & {
|
|
|
|
framesToPop?: number,
|
|
|
|
};
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2017-06-14 16:16:26 +00:00
|
|
|
function parseErrorStack(e: ExtendedError): Array<StackFrame> {
|
2015-06-22 17:08:20 +00:00
|
|
|
if (!e || !e.stack) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
|
|
|
|
* error found when Flow v0.54 was deployed. To see the error delete this
|
|
|
|
* comment and run Flow. */
|
2017-06-14 16:16:26 +00:00
|
|
|
const stacktraceParser = require('stacktrace-parser');
|
2018-05-11 02:06:46 +00:00
|
|
|
const stack = Array.isArray(e.stack)
|
|
|
|
? e.stack
|
|
|
|
: stacktraceParser.parse(e.stack);
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2017-06-14 16:16:26 +00:00
|
|
|
let framesToPop = typeof e.framesToPop === 'number' ? e.framesToPop : 0;
|
2015-01-30 01:10:49 +00:00
|
|
|
while (framesToPop--) {
|
|
|
|
stack.shift();
|
|
|
|
}
|
2015-03-20 15:43:51 +00:00
|
|
|
return stack;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 15:43:51 +00:00
|
|
|
module.exports = parseErrorStack;
|