Catch crash file parsing errors

Reviewed By: passy

Differential Revision: D38940908

fbshipit-source-id: 59f0669311093a4a9c24f570d7e63de0a51f9376
This commit is contained in:
Andrey Goncharov
2022-08-23 08:55:25 -07:00
committed by Facebook GitHub Bot
parent 5aff69d1c9
commit 9b58f5217e

View File

@@ -82,11 +82,16 @@ 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;
} catch (e) {
console.warn('parsePathModern -> failed to parse crash file', e, content);
return null;
}
}
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -127,12 +132,20 @@ export class iOSCrashWatcher extends DeviceListener {
!!checkFileExtensionLegacy,
)
) {
try {
this.device.flipperServer.emit('device-crash', {
crash: checkFileExtensionLegacy
? parseIosCrashLegacy(data)
: parseIosCrashModern(data),
serial: this.device.serial,
});
} catch (e) {
console.error(
'iOSCrashWatcher.startListener -> failed to parse crash file',
e,
data,
);
}
}
});
});