2015-01-30 04:10:49 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-24 01:07:33 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03: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 04:10:49 +03:00
|
|
|
*
|
2018-05-11 05:06:46 +03:00
|
|
|
* @format
|
2016-06-01 23:50:34 +03:00
|
|
|
* @flow
|
2015-01-30 04:10:49 +03:00
|
|
|
*/
|
2018-05-11 05:06:46 +03:00
|
|
|
|
2015-01-30 04:10:49 +03:00
|
|
|
'use strict';
|
|
|
|
|
2019-05-22 23:04:35 +03:00
|
|
|
import type {StackFrame} from '../NativeExceptionsManager';
|
2019-12-02 17:00:09 +03:00
|
|
|
import type {HermesParsedStack} from './parseHermesStack';
|
|
|
|
|
|
|
|
const parseHermesStack = require('./parseHermesStack');
|
2015-01-30 04:10:49 +03:00
|
|
|
|
2017-06-14 19:16:26 +03:00
|
|
|
export type ExtendedError = Error & {
|
2018-09-12 23:55:58 +03:00
|
|
|
jsEngine?: string,
|
2019-06-27 17:55:15 +03:00
|
|
|
preventSymbolication?: boolean,
|
2019-07-31 12:28:40 +03:00
|
|
|
componentStack?: string,
|
2019-11-08 18:39:15 +03:00
|
|
|
forceRedbox?: boolean,
|
2019-11-13 22:30:43 +03:00
|
|
|
isComponentError?: boolean,
|
2019-11-21 20:38:13 +03:00
|
|
|
...
|
2017-06-14 19:16:26 +03:00
|
|
|
};
|
2015-01-30 04:10:49 +03:00
|
|
|
|
2019-12-02 17:00:09 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-14 19:16:26 +03:00
|
|
|
function parseErrorStack(e: ExtendedError): Array<StackFrame> {
|
2015-06-22 20:08:20 +03:00
|
|
|
if (!e || !e.stack) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2017-06-14 19:16:26 +03:00
|
|
|
const stacktraceParser = require('stacktrace-parser');
|
2018-05-11 05:06:46 +03:00
|
|
|
const stack = Array.isArray(e.stack)
|
|
|
|
? e.stack
|
2019-12-02 17:00:09 +03:00
|
|
|
: global.HermesInternal
|
|
|
|
? convertHermesStack(parseHermesStack(e.stack))
|
2020-03-25 07:35:58 +03:00
|
|
|
: stacktraceParser.parse(e.stack).map(frame => ({
|
2019-12-02 17:00:09 +03:00
|
|
|
...frame,
|
|
|
|
column: frame.column != null ? frame.column - 1 : null,
|
|
|
|
}));
|
2015-01-30 04:10:49 +03:00
|
|
|
|
2015-03-20 18:43:51 +03:00
|
|
|
return stack;
|
2015-01-30 04:10:49 +03:00
|
|
|
}
|
|
|
|
|
2015-03-20 18:43:51 +03:00
|
|
|
module.exports = parseErrorStack;
|