Fix iOS crash parsing

Reviewed By: lawrencelomax

Differential Revision: D39058673

fbshipit-source-id: 64065c6d7e9fa96e827419bd6cffbceccc110d89
This commit is contained in:
Andrey Goncharov
2022-09-05 07:46:02 -07:00
committed by Facebook GitHub Bot
parent c854d0a2bb
commit 9c7a53fd05
2 changed files with 21 additions and 12 deletions

View File

@@ -36,7 +36,7 @@ const modernCrashReportPartial = `{"app_name":"Sample","timestamp":"2022-08-02 1
"procExitAbsTime" : 568276773623039, "procExitAbsTime" : 568276773623039,
"cpuType" : "X86-64", "cpuType" : "X86-64",
"procName" : "Sample", "procName" : "Sample",
"procPath" : "\/Users\/USER\/Library\/Developer\/CoreSimulator\/Devices\/543083BF-313B-422B-A817-377078C830AF\/data\/Containers\/Bundle\/Application\/22053C61-10A5-49AE-9B09-00B0B9EAC36B\/Sample.app\/Sample" "procPath" : "\/Users\/USER\/Library\/Developer\/CoreSimulator\/Devices\/543083BF-313B-422B-A817-377078C830AF\/data\/Containers\/Bundle\/Application\/22053C61-10A5-49AE-9B09-00B0B9EAC36B\/Sample.app\/Sample",
}`; }`;
test('test the parsing of the date and crash info for the log which matches the predefined regex', () => { test('test the parsing of the date and crash info for the log which matches the predefined regex', () => {

View File

@@ -43,17 +43,24 @@ export function parseIosCrashLegacy(content: string) {
} }
export function parseIosCrashModern(content: string) { export function parseIosCrashModern(content: string) {
const lines = content.split('\n'); const captureTimeRegex = /"captureTime".*:.*"(.*)",\n/;
// Skip the first line of the .ips file as it is useless const captureTimeArr = captureTimeRegex.exec(content);
const reportBodyString = lines.slice(1).join('\n');
const reportBody = JSON.parse(reportBodyString); const exceptionRegex = /"exception".*:.*{(.*)},\n/;
const exception = `${reportBody.exception.type} (${reportBody.exception.signal})`; const exceptionArr = exceptionRegex.exec(content);
let exceptionJSON: {type: string; signal: string} | undefined;
try {
exceptionJSON = JSON.parse(`{${exceptionArr?.[1]}}`);
} catch {}
const exception = exceptionJSON
? `${exceptionJSON.type} (${exceptionJSON.signal})`
: 'Unknown';
const crash: CrashLog = { const crash: CrashLog = {
callstack: content, callstack: content,
name: exception, name: exception,
reason: exception, reason: exception,
date: new Date(reportBody.captureTime).getTime(), date: new Date(captureTimeArr?.[1] as string).getTime(),
}; };
return crash; return crash;
} }
@@ -83,11 +90,13 @@ export function parsePathLegacy(content: string): string | null {
export function parsePathModern(content: string): string | null { export function parsePathModern(content: string): string | null {
try { try {
const lines = content.split('\n'); const regex = /"procPath".*:.*"(.*)",\n/;
// Skip the first line of the .ips file as it is useless const arr = regex.exec(content);
const reportBodyString = lines.slice(1).join('\n'); if (!arr || arr.length <= 1) {
const reportBody = JSON.parse(reportBodyString); return null;
return reportBody.procPath; }
const path = arr[1];
return path.trim();
} catch (e) { } catch (e) {
console.warn('parsePathModern -> failed to parse crash file', e, content); console.warn('parsePathModern -> failed to parse crash file', e, content);
return null; return null;