Crashreporter Plugin

Summary: Desktop side of Crash reporter plugin

Reviewed By: jknoxville

Differential Revision: D13176724

fbshipit-source-id: d77b86b2bd9c78c0626f2e3b8c0057227d75e2b2
This commit is contained in:
Pritesh Nandgaonkar
2018-11-26 03:41:16 -08:00
committed by Facebook Github Bot
parent 19485d076b
commit 543bc6c4fb
4 changed files with 10543 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
* @flow
*/
import {FlipperPlugin} from 'flipper';
import type {Notification} from '../../plugin';
type Crash = {|
notificationID: number,
callStack: [string],
reason: string,
name: string,
|};
type PersistedState = {|
crashes: Array<Crash>,
|};
export default class extends FlipperPlugin {
static title = 'Crash Reporter';
static id = 'CrashReporter';
static icon = 'apps';
static defaultPersistedState = {
crashes: [],
};
/*
* Reducer to process incoming "send" messages from the mobile counterpart.
*/
static persistedStateReducer = (
persistedState: PersistedState,
method: string,
payload: Object,
): PersistedState => {
if (method === 'crash-report') {
return {
...persistedState,
crashes: persistedState.crashes.concat([
{
notificationID: Math.random(), // All notifications are unique
callStack: payload.callstack,
name: payload.name,
reason: payload.reason,
},
]),
};
}
return persistedState;
};
/*
* Callback to provide the currently active notifications.
*/
static getActiveNotifications = (
persistedState: PersistedState,
): Array<Notification> => {
return persistedState.crashes.map((crash: Crash) => {
return {
id: 'crash-notification:' + crash.notificationID,
message: crash.callStack,
severity: 'error',
title: 'CRASH: ' + crash.name + ' ' + crash.reason,
};
});
};
render() {
return 'Dedicated space to debug crashes. Look out for crash notifications.';
}
}