Only pass Error.stack to parseErrorStack

Summary:
I want to be able parse error stacks in contexts where I have a call stack string but no error object.

This diff changes parseErrorStack to only accept the stack, instead of a whole error object.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D22752048

fbshipit-source-id: b4b1cd58802eefe736130d48a82bc091241a11ee
This commit is contained in:
Rick Hanlon
2020-07-27 13:57:58 -07:00
committed by Facebook GitHub Bot
parent cd6e2b468d
commit 9edfc43aad
5 changed files with 13 additions and 14 deletions
+7 -7
View File
@@ -47,22 +47,22 @@ function convertHermesStack(stack: HermesParsedStack): Array<StackFrame> {
return frames;
}
function parseErrorStack(e: ExtendedError): Array<StackFrame> {
if (!e || !e.stack) {
function parseErrorStack(errorStack?: string): Array<StackFrame> {
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;