This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from pylon/ndw-gurpsee
ExceptionHandler to catch known GPRC bug while we wait for an upstream fix
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
android/src/main/java/com/pylon/RNSpokestack/ExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |