Change internal storage to number instead of Date

Summary: per title, for reasons see next diff :)

Reviewed By: passy

Differential Revision: D29327501

fbshipit-source-id: 548d943e90769af478232d3031d916fb399a067a
This commit is contained in:
Michel Weststrate
2021-06-29 08:02:53 -07:00
committed by Facebook GitHub Bot
parent d02c560150
commit aff02b2ca1
5 changed files with 24 additions and 18 deletions

View File

@@ -35,7 +35,9 @@ export function Crashes() {
items={crashes.map((crash) => ({ items={crashes.map((crash) => ({
id: crash.notificationID, id: crash.notificationID,
title: crash.reason ?? crash.name, title: crash.reason ?? crash.name,
description: `${crash.date.toLocaleString()} - ${crash.name}`, description: `${new Date(crash.date).toLocaleString()} - ${
crash.name
}`,
}))} }))}
selection={selectedCrashId} selection={selectedCrashId}
onSelect={(id) => { onSelect={(id) => {

View File

@@ -8,7 +8,7 @@
*/ */
import {BaseDevice} from 'flipper'; import {BaseDevice} from 'flipper';
import {Crash} from '../index'; import {Crash, CrashLog} from '../index';
import {TestUtils} from 'flipper-plugin'; import {TestUtils} from 'flipper-plugin';
import {getPluginKey} from 'flipper'; import {getPluginKey} from 'flipper';
import * as CrashReporterPlugin from '../index'; import * as CrashReporterPlugin from '../index';
@@ -24,13 +24,13 @@ function getCrash(
callstack: string, callstack: string,
name: string, name: string,
reason: string, reason: string,
): Crash { ): Crash & CrashLog {
return { return {
notificationID: id.toString(), notificationID: id.toString(),
callstack: callstack, callstack: callstack,
reason: reason, reason: reason,
name: name, name: name,
date: new Date(), date: new Date().getTime(),
}; };
} }
@@ -40,7 +40,7 @@ function assertCrash(crash: Crash, expectedCrash: Crash) {
expect(callstack).toEqual(expectedCrash.callstack); expect(callstack).toEqual(expectedCrash.callstack);
expect(reason).toEqual(expectedCrash.reason); expect(reason).toEqual(expectedCrash.reason);
expect(name).toEqual(expectedCrash.name); expect(name).toEqual(expectedCrash.name);
expect(date.toDateString()).toEqual(expectedCrash.date.toDateString()); expect(Math.abs(date - expectedCrash.date)).toBeLessThan(1000);
} }
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', () => {
@@ -50,7 +50,7 @@ test('test the parsing of the date and crash info for the log which matches the
expect(crash.callstack).toEqual(log); expect(crash.callstack).toEqual(log);
expect(crash.reason).toEqual('SIGSEGV'); expect(crash.reason).toEqual('SIGSEGV');
expect(crash.name).toEqual('SIGSEGV'); expect(crash.name).toEqual('SIGSEGV');
expect(crash.date).toEqual(new Date('2019-03-21 12:07:00.861')); expect(crash.date).toEqual(new Date('2019-03-21 12:07:00.861').getTime());
}); });
test('test the parsing of the reason for crash when log matches the crash regex, but there is no mention of date', () => { test('test the parsing of the reason for crash when log matches the crash regex, but there is no mention of date', () => {
@@ -95,7 +95,7 @@ test('test the parsing of the Android crash log for the proper android crash for
'java.lang.IndexOutOfBoundsException: Index: 190, Size: 0', 'java.lang.IndexOutOfBoundsException: Index: 190, Size: 0',
); );
expect(crash.name).toEqual('FATAL EXCEPTION: main'); expect(crash.name).toEqual('FATAL EXCEPTION: main');
expect(crash.date).toEqual(date); expect(crash.date).toEqual(date.getTime());
}); });
test('test the parsing of the Android crash log for the unknown crash format and no date', () => { test('test the parsing of the Android crash log for the unknown crash format and no date', () => {
const log = 'Blaa Blaa Blaa'; const log = 'Blaa Blaa Blaa';
@@ -147,7 +147,9 @@ test('test helper setdefaultPersistedState function', () => {
const crash = getCrash(0, 'callstack', 'crash0', 'crash0'); const crash = getCrash(0, 'callstack', 'crash0', 'crash0');
const plugin = TestUtils.startDevicePlugin(CrashReporterPlugin); const plugin = TestUtils.startDevicePlugin(CrashReporterPlugin);
plugin.instance.reportCrash(crash); plugin.instance.reportCrash(crash);
expect(plugin.exportState()).toEqual({crashes: [crash]}); expect(plugin.exportState()).toEqual({
crashes: [crash],
});
}); });
test('test getNewPersistedStateFromCrashLog for non-empty defaultPersistedState and defined pluginState', () => { test('test getNewPersistedStateFromCrashLog for non-empty defaultPersistedState and defined pluginState', () => {
const crash = getCrash(0, 'callstack', 'crash0', 'crash0'); const crash = getCrash(0, 'callstack', 'crash0', 'crash0');

View File

@@ -9,7 +9,7 @@
import type {DeviceLogEntry, DevicePluginClient} from 'flipper-plugin'; import type {DeviceLogEntry, DevicePluginClient} from 'flipper-plugin';
import {UNKNOWN_CRASH_REASON} from './crash-utils'; import {UNKNOWN_CRASH_REASON} from './crash-utils';
import type {Crash, CrashLog} from './index'; import type {CrashLog} from './index';
export function parseAndroidCrash(content: string, logDate?: Date) { export function parseAndroidCrash(content: string, logDate?: Date) {
const regForName = /.*\n/; const regForName = /.*\n/;
@@ -35,7 +35,7 @@ export function parseAndroidCrash(content: string, logDate?: Date) {
callstack: content, callstack: content,
name: name, name: name,
reason: reason, reason: reason,
date: logDate, date: logDate?.getTime(),
}; };
return crash; return crash;
} }
@@ -53,7 +53,7 @@ export function shouldParseAndroidLog(
export function startAndroidCrashWatcher( export function startAndroidCrashWatcher(
client: DevicePluginClient, client: DevicePluginClient,
reportCrash: (payload: CrashLog | Crash) => void, reportCrash: (payload: CrashLog) => void,
) { ) {
const referenceDate = new Date(); const referenceDate = new Date();
let androidLog: string = ''; let androidLog: string = '';

View File

@@ -18,14 +18,14 @@ export type Crash = {
callstack?: string; callstack?: string;
reason: string; reason: string;
name: string; name: string;
date: Date; date: number;
}; };
export type CrashLog = { export type CrashLog = {
callstack: string; callstack: string;
reason: string; reason: string;
name: string; name: string;
date?: Date | null; date?: number;
}; };
export function devicePlugin(client: DevicePluginClient) { export function devicePlugin(client: DevicePluginClient) {
@@ -39,7 +39,7 @@ export function devicePlugin(client: DevicePluginClient) {
selectedCrash.set(crashId as string); selectedCrash.set(crashId as string);
}); });
function reportCrash(payload: CrashLog | Crash) { function reportCrash(payload: CrashLog) {
notificationID++; notificationID++;
const crash = { const crash = {
@@ -47,7 +47,7 @@ export function devicePlugin(client: DevicePluginClient) {
callstack: payload.callstack, callstack: payload.callstack,
name: payload.name, name: payload.name,
reason: payload.reason, reason: payload.reason,
date: payload.date || new Date(), date: payload.date ?? Date.now(),
}; };
crashes.update((draft) => { crashes.update((draft) => {

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import type {Crash, CrashLog} from './index'; import type {CrashLog} from './index';
import fs from 'fs'; import fs from 'fs';
import os from 'os'; import os from 'os';
import path from 'path'; import path from 'path';
@@ -29,7 +29,9 @@ export function parseIosCrash(content: string) {
const tmp1 = dateRegex2.exec(dateString); const tmp1 = dateRegex2.exec(dateString);
const extractedDateString: string | null = const extractedDateString: string | null =
tmp1 && tmp1[0].length ? tmp1[0] : null; tmp1 && tmp1[0].length ? tmp1[0] : null;
const date = extractedDateString ? new Date(extractedDateString) : new Date(); const date = extractedDateString
? new Date(extractedDateString).getTime()
: Date.now();
const crash: CrashLog = { const crash: CrashLog = {
callstack: content, callstack: content,
@@ -64,7 +66,7 @@ export function parsePath(content: string): string | null {
export function addFileWatcherForiOSCrashLogs( export function addFileWatcherForiOSCrashLogs(
serial: string, serial: string,
reportCrash: (payload: CrashLog | Crash) => void, reportCrash: (payload: CrashLog) => void,
) { ) {
const dir = path.join(os.homedir(), 'Library', 'Logs', 'DiagnosticReports'); const dir = path.join(os.homedir(), 'Library', 'Logs', 'DiagnosticReports');
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {