找到项目中缺失的onError

Find missing onError in the project

我正在尝试找到项目中丢失的 onError()。这意味着应用程序崩溃是因为订阅不处理 throwable,所以我想找到该订阅并添加 onError 方法。

不幸的是,堆栈跟踪在这里并不是很有用,它只显示 throw new IOException 的行,仅此而已:

 FATAL EXCEPTION: main
    Process: my.app.example.dev, PID: 20309
    java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:54)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
            at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)
            at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)
            at rx.android.app.OperatorConditionalBinding.onError(OperatorConditionalBinding.java:69)
            at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access[=10=]0(OperatorObserveOn.java:65)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:153)
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: rx.exceptions.CompositeException: 2 exceptions occurred.
            at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)
            at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)
            at rx.android.app.OperatorConditionalBinding.onError(OperatorConditionalBinding.java:69)
            at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access[=10=]0(OperatorObserveOn.java:65)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:153)
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =>
            at com.splunk.mint.ExceptionHandler.uncaughtException(ExceptionHandler.java:42)
            at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
            at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:58)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: retrofit.RetrofitError: java.io.IOException: No connectivity
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:385)
            at retrofit.RestAdapter$RestHandler.access0(RestAdapter.java:221)
            at retrofit.RestAdapter$RestHandler.call(RestAdapter.java:271)
            at retrofit.RestAdapter$RestHandler.call(RestAdapter.java:269)
            at retrofit.RxSupport.run(RxSupport.java:46)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
     Caused by: java.io.IOException: No connectivity
            at my.app.example.manager.ApiManager$NetworkAwareOKClient.execute(ApiManager.java:1071)
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:322)
            at retrofit.RestAdapter$RestHandler.access0(RestAdapter.java:221)
            at retrofit.RestAdapter$RestHandler.call(RestAdapter.java:271)
            at retrofit.RestAdapter$RestHandler.call(RestAdapter.java:269)
            at retrofit.RxSupport.run(RxSupport.java:46)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)

有没有找到没有 onError() 的订阅(代码行)的想法?

这可能很难调试。有趣的是,我在 Action1<Throwable> [facepalm].

中出错了

最好的调试方法是注册一个全局错误处理程序。这将使您在代码中看到真相:

RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
        @Override
        public void handleError(Throwable e) {
            Log.w("Error",e);
        }
});    

关于 github 的讨论:https://github.com/ReactiveX/RxJava/issues/2293

如果 onError 没有实现,那么 RxJava 会抛出一个 OnErrorNotImplementedException 异常。看来 RxJava 没有成功调用 onError 方法 ("Error occurred when trying to propagate error to Observer.onError")

您可以尝试注册一个错误处理程序来查找根异常。

static {
    RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
        @Override
        public void handleError(Throwable e) {
            e.printStackTrace();
        }
    });
}

使用这个:

RxJavaHooks.setOnError(throwable -> {
    if (throwable != null && throwable.getMessage() != null) {
        Log.e("Error", throwable.getMessage());
    }
});

而不是弃用 RxJavaPlugins.getInstance()