Skip to content
This repository has been archived by the owner on Aug 9, 2020. It is now read-only.

Misleading exception when cache directory does not exist #57

Closed
daemontus opened this issue Aug 25, 2016 · 3 comments
Closed

Misleading exception when cache directory does not exist #57

daemontus opened this issue Aug 25, 2016 · 3 comments
Labels

Comments

@daemontus
Copy link
Contributor

Hi, this is a minor thing, but I recently discovered that if you configure RxCache with a directory that does not exist (but can be created - so there are no access rights issues, someone just needs to call mkdirs on it), you are going to get the following exception:

io.rx_cache.RxCacheException: The Loader provided did not return any data and there is not data to load from the Cache getEpisodes
(Plus a very very long stack trace of course)

This I find a little dangerous, because it makes you start debugging the wrong parts of your code. :D Only if you go through the whole stack trace, on the bottom you can see that that it was caused by a file not found error. And even that isn't a very good hint, because if you don't know how the persistent cache works internally, you are going to assume that this just means there indeed isn't any data cached.

So I would propose to either:

  • Make sure the directory exists and is writeable right during the configuration phase
  • Or make the error handling a bit more flexible so that not everything looks like it was caused by an empty loader

(And I'll gladly make a pull request, just tell me which one seems better to you)

@daemontus daemontus changed the title RxCacheException when cache directory does not exist Misleading exception when cache directory does not exist Aug 25, 2016
@VictorAlbertos
Copy link
Owner

Hi @daemontus

First, thanks for the feedback.

I think the first approach should be done, because the second one is going to be harder to implement. Plus, making the app crash as soon as possible it seems to be a better way to deal with errors ;)

At this line the new validation must be add:
https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/internal/RxCache.java#L84

And you need to write a unit test asserting to failure in order to test that the new validation works properly.

So, the PR will be very welcome :)

And just a few questions:

Are you using RxCache on Android?
Exactly what path are you supplying?

Thanks!

@daemontus
Copy link
Contributor Author

Cool, I'll try to do it sometime next week.

Regarding the usage: Yes, it's Android. It was just a subdirectory of the default cache folder -File(context.getCacheDir(), "some_subdir") - I was playing with different caching libraries at the same time and thought it would be a good idea to separate them from each other, just in case :)

@VictorAlbertos
Copy link
Owner

Thanks ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants