Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #44 from pylon/ndw-gurpsee
Browse files Browse the repository at this point in the history
ExceptionHandler to catch known GPRC bug while we wait for an upstream fix
  • Loading branch information
noelweichbrodt committed Mar 25, 2019
2 parents 9b09d06 + fecf45a commit 6ee9653
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions android/src/main/java/com/pylon/RNSpokestack/ExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.pylon.RNSpokestack;

import android.content.Context;
import android.util.Log;

/* Our very own exception handler for all threads with us as the parent process.
* https://github.com/googleapis/google-cloud-java/issues/4727 necessitates this.
* Hence we silently swallow the specific exception, and let the default exception handler
* do its thing otherwise.
*/
public class ExceptionHandler implements Thread.UncaughtExceptionHandler {

private Context context;
private Thread.UncaughtExceptionHandler rootHandler;

public GlobalExceptionHandler(Context context) {
this.context = context;
this.rootHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
}

/* The specific exception to ignore stems from grpc-okhttp-1, which is present in google-cloud-speech 0.84.0-beta.
* https://github.com/grpc/grpc-java/blob/master/okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java#L933
*/
@Override
public void uncaughtException(final Thread thread, final Throwable ex) {
if (this.rootHandler != null && ex instanceof java.util.concurrent.RejectedExecutionException) {
Log.i("react-native-spokestack","ignoring known exception: " + ex.toString());
} else if (this.rootHandler != null) {
this.rootHandler.uncaughtException(thread, ex);
} else {
Log.e("react-native-spokestack","no root handlerfor uncaught exception, killing process and exiting.");
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
}
}

0 comments on commit 6ee9653

Please sign in to comment.