-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stack tracing & Crash reports work in progress - testing
- Loading branch information
Showing
16 changed files
with
383 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const CALLEE_EXCLUDE = [ | ||
'Object.dispatch', | ||
'dispatch', | ||
'HTMLUnknownElement.callCallback', | ||
'Object.invokeGuardedCallbackDev', | ||
'invokeGuardedCallback', | ||
'invokeGuardedCallbackAndCatchFirstError', | ||
'executeDispatch', | ||
'processDispatchQueueItemsInOrder', | ||
'processDispatchQueue', | ||
'dispatchEventsForPlugins', | ||
'batchedEventUpdates$1', | ||
'batchedEventUpdates', | ||
'scheduler.development.js', | ||
'trace', | ||
'logger.ts', | ||
'unstable_runWithPriority', | ||
'Object.captureEvent' | ||
]; | ||
|
||
export const FILE_NAME_EXCLUDE = [ | ||
'logger.ts', | ||
'react-dom.development.js', | ||
'serializableStateInvariantMiddleware.ts', | ||
'Connector.ts' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { getEnvironmentPlatform } from "../helpers/platform"; | ||
import { StackTraceData } from "../types"; | ||
import { CALLEE_EXCLUDE, FILE_NAME_EXCLUDE } from "./constants"; | ||
import { filterStack, prepareStack } from "./stackTraceyHelpers"; | ||
import { parseRawStack, filterStack as filterSimpleStack, prepareStack as prepareSimpleStack } from "./simpleTracing"; | ||
import StackTracey from 'stacktracey'; | ||
|
||
export const getStackTrace = async (errorOrStack: Error | string | undefined): Promise<StackTraceData> => { | ||
const environmentPlatform = getEnvironmentPlatform(); | ||
const stackStr = (errorOrStack instanceof Error) ? errorOrStack.stack : errorOrStack; | ||
|
||
switch (environmentPlatform) { | ||
case "nodejs": { | ||
const stack = new StackTracey(stackStr); | ||
const stackWithSource = stack.withSources(); | ||
|
||
const filteredStack = filterStack(stackWithSource, CALLEE_EXCLUDE, FILE_NAME_EXCLUDE); | ||
const preparedStack = prepareStack(filteredStack); | ||
|
||
return { stack: preparedStack }; | ||
} | ||
case "web": { | ||
const stack = new StackTracey(stackStr); | ||
const stackWithSource = await stack.withSourcesAsync(); | ||
|
||
const filteredStack = filterStack(stackWithSource, CALLEE_EXCLUDE, FILE_NAME_EXCLUDE); | ||
const preparedStack = prepareStack(filteredStack); | ||
|
||
return { stack: preparedStack }; | ||
} | ||
case "react-native": { | ||
const stack = parseRawStack(stackStr); | ||
const filteredStack = filterSimpleStack(stack, CALLEE_EXCLUDE, FILE_NAME_EXCLUDE); | ||
const preparedStack = prepareSimpleStack(filteredStack); | ||
|
||
return { stack: preparedStack }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { StackTraceCallData } from "../types"; | ||
|
||
export const nixSlashes = (x: string) => x.replace (/\\/g, '/'); | ||
|
||
type SimpleParsedStack = { | ||
beforeParse: string; | ||
callee: string; | ||
native: boolean; | ||
file: string; | ||
line: number | undefined; | ||
column: number | undefined; | ||
}[]; | ||
|
||
// Based on stacktracey rawParse method | ||
export const parseRawStack = (str: string = ""): SimpleParsedStack => { | ||
const lines = str.split('\n'); | ||
|
||
const entries = lines.map(line => { | ||
line = line.trim(); | ||
|
||
let callee, fileLineColumn = [], native, planA, planB; | ||
|
||
if ((planA = line.match (/at (.+) \(eval at .+ \((.+)\), .+\)/)) || // eval calls | ||
(planA = line.match (/at (.+) \((.+)\)/)) || | ||
((line.slice (0, 3) !== 'at ') && (planA = line.match (/(.*)@(.*)/)))) { | ||
|
||
callee = planA[1]; | ||
native = (planA[2] === 'native'); | ||
fileLineColumn = (planA[2].match (/(.*):(\d+):(\d+)/) || planA[2].match (/(.*):(\d+)/) || []).slice(1); | ||
|
||
} else if ((planB = line.match (/^(at\s+)*(.+):(\d+):(\d+)/) )) { | ||
fileLineColumn = (planB).slice (2) | ||
} else { | ||
return undefined | ||
} | ||
|
||
if (callee && !fileLineColumn[0]) { | ||
const type = callee.split ('.')[0]; | ||
if (type === 'Array') { | ||
native = true; | ||
} | ||
} | ||
|
||
return { | ||
beforeParse: line, | ||
callee: callee || '', | ||
native: native || false, | ||
file: nixSlashes(fileLineColumn[0] || ''), | ||
line: parseInt(fileLineColumn[1] || '', 10) || undefined, | ||
column: parseInt(fileLineColumn[2] || '', 10) || undefined | ||
} | ||
}); | ||
|
||
return entries.filter(x => (x !== undefined)) as SimpleParsedStack; | ||
}; | ||
|
||
export const filterStack = (stack: SimpleParsedStack, calleeExclude: string[], fileNameExclude: string[]) => { | ||
return stack.filter((a) => { | ||
let fileExcluded = false; | ||
|
||
for (const fileName of fileNameExclude) { | ||
if (a.file.includes(fileName)) { | ||
fileExcluded = true; | ||
break; | ||
} | ||
} | ||
|
||
return !calleeExclude.includes(a.callee) && !fileExcluded && !a.file.includes('node_modules'); | ||
}); | ||
} | ||
|
||
export const prepareStack = (stack: SimpleParsedStack): StackTraceCallData[] => { | ||
return stack.map((a) => ({ | ||
beforeParse: a.beforeParse, | ||
callee: a.callee, | ||
native: a.native, | ||
file: a.file, | ||
line: a.line | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import StackTracey from "stacktracey"; | ||
import { StackTraceCallData } from "../types"; | ||
|
||
export const filterStack = (stackWithSource: StackTracey, calleeExclude: string[], fileNameExclude: string[]): StackTracey => { | ||
return stackWithSource.filter((a) => !calleeExclude.includes(a.callee) && !fileNameExclude.includes(a.fileName) && !a.file.includes('node_modules')); | ||
}; | ||
|
||
export const prepareStack = (stackWithSource: StackTracey): StackTraceCallData[] => { | ||
return stackWithSource.items.map((a) => ({ | ||
sourceLine: a.sourceLine, | ||
beforeParse: a.beforeParse, | ||
callee: a.callee, | ||
calleeShort: a.calleeShort, | ||
native: a.native, | ||
fileRelative: a.fileRelative, | ||
fileShort: a.fileShort, | ||
fileName: a.fileName, | ||
line: a.line | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.