RxDogTag RxJava 未处理错误的标识程序开源项目

我要开发同款
匿名用户2019年05月12日
46阅读
开发技术Kotlin
所属分类常用工具包、程序开发
授权协议Apache

作品详情

RxDogTag是一个用于标记RxJava2观察者中的原始订阅点的实用程序,其目标是在出现未处理错误的情况下显示其订阅位置以便稍后进行错误报告/调查。这仅适用于未实现onError()的RxJava观察者。

请看如下经典的RxJava错误:

Observable.range(0,10).subscribeOn(Schedulers.io()).map(i->null).subscribe();

这是RxJava并发中非常常见的问题,没有标识的话,会产生如下的异常信息:

io.reactivex.exceptions.OnErrorNotImplementedException:TheexceptionwasnothandledduetomissingonErrorhandlerinthesubscribe()methodcall.Furtherreading:https://github.com/ReactiveX/RxJava/wiki/Error-Handling|Themapperfunctionreturnedanullvalue.atio.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)atio.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)atio.reactivex.internal.observers.LambdaObserver.onError(LambdaObserver.java:77)atio.reactivex.internal.observers.BasicFuseableObserver.onError(BasicFuseableObserver.java:100)atio.reactivex.internal.observers.BasicFuseableObserver.fail(BasicFuseableObserver.java:110)atio.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:59)atio.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeOnObserver.onNext(ObservableSubscribeOn.java:58)atio.reactivex.internal.operators.observable.ObservableScalarXMap$ScalarDisposable.run(ObservableScalarXMap.java:248)atio.reactivex.internal.operators.observable.ObservableJust.subscribeActual(ObservableJust.java:35)atio.reactivex.Observable.subscribe(Observable.java:12090)atio.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)atio.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)atio.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)atio.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)atjava.util.concurrent.FutureTask.run(FutureTask.java:266)atjava.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)atjava.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)atjava.lang.Thread.run(Thread.java:748)Causedby:java.lang.NullPointerException:Themapperfunctionreturnedanullvalue.atio.reactivex.internal.functions.ObjectHelper.requireNonNull(ObjectHelper.java:39)atio.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:57)...14more

你很难从这份报告中清楚的了解实际的状况。

而启用了RxDogTag后,相同的错误变成:

io.reactivex.exceptions.OnErrorNotImplementedException:Themapperfunctionreturnedanullvalue.Causedby:java.lang.NullPointerException:Themapperfunctionreturnedanullvalue.at[[Inferredsubscribepoint]].(:0)atcom.uber.anotherpackage.ReadMeExample.complex(ReadMeExample.java:55)at[[Originaltrace]].(:0)atio.reactivex.internal.functions.ObjectHelper.requireNonNull(ObjectHelper.java:39)atio.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:57)atio.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeOnObserver.onNext(ObservableSubscribeOn.java:58)atio.reactivex.internal.operators.observable.ObservableScalarXMap$ScalarDisposable.run(ObservableScalarXMap.java:248)atio.reactivex.internal.operators.observable.ObservableJust.subscribeActual(ObservableJust.java:35)atio.reactivex.Observable.subscribe(Observable.java:12090)atio.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)atio.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)atio.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)atio.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)atjava.util.concurrent.FutureTask.run(FutureTask.java:266)atjava.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)atjava.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)atjava.lang.Thread.run(Thread.java:748)

这样我们就知道这个错误对应的代码是 ReadMeExample.java:55.这并非找出问题根源的银弹,但至少你知道错误在哪里。

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论