在项目中找到缺少的onError

时间:2015-02-10 14:15:20

标签: android rx-java

我正在尝试在项目中找到丢失的onError()。这意味着应用程序崩溃,因为订阅不处理throwables所以我想找到该订阅并添加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$1.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$000(OperatorObserveOn.java:65)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.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$1.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$000(OperatorObserveOn.java:65)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.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.access$100(RestAdapter.java:221)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:271)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:269)
            at retrofit.RxSupport$2.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.access$100(RestAdapter.java:221)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:271)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:269)
            at retrofit.RxSupport$2.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()的订阅(代码行)的任何想法?

3 个答案:

答案 0 :(得分:23)

这可能是一个痛苦的调试。有趣的是,我在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

答案 1 :(得分:1)

如果未实现onError,则RxJava会抛出OnErrorNotImplementedException异常。似乎RxJava没有成功调用onError方法(“尝试将错误传播到Observer.onError时发生错误”)

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

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

答案 2 :(得分:0)

使用这个:

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

代替不推荐使用的RxJavaPlugins.getInstance()