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) => ({
id: crash.notificationID,
title: crash.reason ?? crash.name,
description: `${crash.date.toLocaleString()} - ${crash.name}`,
description: `${new Date(crash.date).toLocaleString()} - ${
crash.name
}`,
}))}
selection={selectedCrashId}
onSelect={(id) => {

View File

@@ -8,7 +8,7 @@
*/
import {BaseDevice} from 'flipper';
import {Crash} from '../index';
import {Crash, CrashLog} from '../index';
import {TestUtils} from 'flipper-plugin';
import {getPluginKey} from 'flipper';
import * as CrashReporterPlugin from '../index';
@@ -24,13 +24,13 @@ function getCrash(
callstack: string,
name: string,
reason: string,
): Crash {
): Crash & CrashLog {
return {
notificationID: id.toString(),
callstack: callstack,
reason: reason,
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(reason).toEqual(expectedCrash.reason);
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', () => {
@@ -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.reason).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', () => {
@@ -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',
);
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', () => {
const log = 'Blaa Blaa Blaa';
@@ -147,7 +147,9 @@ test('test helper setdefaultPersistedState function', () => {
const crash = getCrash(0, 'callstack', 'crash0', 'crash0');
const plugin = TestUtils.startDevicePlugin(CrashReporterPlugin);
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', () => {
const crash = getCrash(0, 'callstack', 'crash0', 'crash0');

View File

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

View File

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

View File

@@ -7,7 +7,7 @@
* @format
*/
import type {Crash, CrashLog} from './index';
import type {CrashLog} from './index';
import fs from 'fs';
import os from 'os';
import path from 'path';
@@ -29,7 +29,9 @@ export function parseIosCrash(content: string) {
const tmp1 = dateRegex2.exec(dateString);
const extractedDateString: string | 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 = {
callstack: content,
@@ -64,7 +66,7 @@ export function parsePath(content: string): string | null {
export function addFileWatcherForiOSCrashLogs(
serial: string,
reportCrash: (payload: CrashLog | Crash) => void,
reportCrash: (payload: CrashLog) => void,
) {
const dir = path.join(os.homedir(), 'Library', 'Logs', 'DiagnosticReports');
if (!fs.existsSync(dir)) {