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,
"cpuType" : "X86-64",
"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', () => {

View File

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