VictorAlbertos / ReactiveCache

A reactive cache for Android and Java which honors the reactive chain.
Apache License 2.0
240 stars 24 forks source link

Do not swallow original exception, but provide it as a cause for debugging #24

Closed AlexTrotsenko closed 4 years ago

AlexTrotsenko commented 6 years ago

When exception is thrown from Observable/Single... and there is not data in the cache - initial exception is swallowed making it's hard to debug possible issue.

Right now when I have:

            Loader.load(config)
                    .subscribeOn(Schedulers.io())
                    .map(params -> {
                        ...
                        return map;
                    })
                    .subscribe(
                            this::foo,
                            e -> {
                                Log.e(TAG, "Unable to execute loader", e);
                            }
                    );

If the exception is thrown from Loader.load() and there is not data in the cache - the original exception is swallowed and replaced with:

    io.rx_cache2.RxCacheException: The Loader provided did not return any data and there is not data to load from the Cache home
        at io.rx_cache2.internal.ProcessorProvidersBehaviour$5.apply(ProcessorProvidersBehaviour.java:148)
        at io.reactivex.internal.operators.observable.ObservableOnErrorReturn$OnErrorReturnObserver.onError(ObservableOnErrorReturn.java:73)
        at io.reactivex.internal.observers.BasicFuseableObserver.onError(BasicFuseableObserver.java:100)
        at io.reactivex.internal.disposables.EmptyDisposable.error(EmptyDisposable.java:63)
        at io.reactivex.internal.operators.observable.ObservableError.subscribeActual(ObservableError.java:37)
        at io.reactivex.Observable.subscribe(Observable.java:10955)
        ...
     Caused by: io.reactivecache2.ExceptionAdapter$PlaceHolderLoader
        at io.reactivecache2.ExceptionAdapter.placeholderLoader(ExceptionAdapter.java:42)
        at io.reactivecache2.Provider.lambda$read$3(Provider.java:71)
        at io.reactivecache2.Provider$$Lambda$3.call(Unknown Source)
        at io.reactivex.internal.operators.single.SingleDefer.subscribeActual(SingleDefer.java:36)
        at io.reactivex.Single.subscribe(Single.java:2779) 
        ...

It makes sense for debugging purposes to add original exception as the cause.

AlexTrotsenko commented 6 years ago

As far as I see, the only place where the error message comes from is https://github.com/VictorAlbertos/RxCache/blob/fb1964b4d38c9f590d8c38827702acd74adfac1c/core/src/main/java/io/rx_cache2/internal/ProcessorProvidersBehaviour.java#L124-L146

VictorAlbertos commented 4 years ago

Feel free to open a PR to improve it 👍