Send notifications on litho's error boundary

Summary: Sends notifications to crash reportr plugin whenever the error boundary happens

Reviewed By: danielbuechele

Differential Revision: D13307473

fbshipit-source-id: dc0c6d2ebac32881fdb1aa5f63def824a115cf9e
This commit is contained in:
Pritesh Nandgaonkar
2018-12-04 05:50:02 -08:00
committed by Facebook Github Bot
parent d331ec2f10
commit 9cfa1b3074
2 changed files with 37 additions and 26 deletions

View File

@@ -1,9 +1,8 @@
/*
* Copyright (c) Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.facebook.flipper.sample;
@@ -65,7 +64,7 @@ public class FlipperSampleApplication extends Application {
new SharedPreferencesDescriptor("other_sample", Context.MODE_PRIVATE))));
client.addPlugin(new LeakCanaryFlipperPlugin());
client.addPlugin(new ExampleFlipperPlugin());
client.addPlugin(new CrashReporterPlugin());
client.addPlugin(CrashReporterPlugin.getInstance());
client.start();
getSharedPreferences("sample", Context.MODE_PRIVATE).edit().putString("Hello", "world").apply();

View File

@@ -1,9 +1,8 @@
/*
* Copyright (c) Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.facebook.flipper.plugins.crashreporter;
@@ -22,7 +21,16 @@ public class CrashReporterPlugin implements FlipperPlugin {
@Nullable private FlipperConnection mConnection;
@Nullable private Thread.UncaughtExceptionHandler prevHandler;
private static CrashReporterPlugin crashreporterPlugin = null;
private CrashReporterPlugin() {}
// static method to create instance of Singleton class
public static CrashReporterPlugin getInstance() {
if (crashreporterPlugin == null) crashreporterPlugin = new CrashReporterPlugin();
return crashreporterPlugin;
}
/*
* Activity to be used to display incoming messages
*/
@@ -38,21 +46,7 @@ public class CrashReporterPlugin implements FlipperPlugin {
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
if (mConnection != null) {
FlipperConnection connection = mConnection;
FlipperArray.Builder builder = new FlipperArray.Builder();
for (StackTraceElement stackTraceElement : paramThrowable.getStackTrace()) {
builder.put(stackTraceElement.toString());
}
FlipperArray arr = builder.build();
connection.send(
"crash-report",
new FlipperObject.Builder()
.put("callstack", arr)
.put("name", paramThrowable.toString())
.put("reason", paramThrowable.getMessage())
.build());
}
sendExceptionMessage(paramThread, paramThrowable);
if (prevHandler != null) {
prevHandler.uncaughtException(paramThread, paramThrowable);
}
@@ -60,6 +54,24 @@ public class CrashReporterPlugin implements FlipperPlugin {
});
}
public void sendExceptionMessage(Thread paramThread, Throwable paramThrowable) {
if (mConnection != null) {
FlipperConnection connection = mConnection;
FlipperArray.Builder builder = new FlipperArray.Builder();
for (StackTraceElement stackTraceElement : paramThrowable.getStackTrace()) {
builder.put(stackTraceElement.toString());
}
FlipperArray arr = builder.build();
connection.send(
"crash-report",
new FlipperObject.Builder()
.put("callstack", arr)
.put("name", paramThrowable.toString())
.put("reason", paramThrowable.getMessage())
.build());
}
}
@Override
public void onDisconnect() {
mConnection = null;