Last week I wrote a cautionary post about using @JvmOverloads on constructors of View-derived classes in Kotlin. This time, I have a quick tidbit to share about improving RxJava stack traces.
But first, a quick update on last week's post - I have filed an official Android Studio bug report asking them to improve the way "quick fix" works for generating view constructors (based on my last tidbit) - please ⭐️ this issue if it's something you'd like to see fixed as well! https://issuetracker.google.com/issues/149986188
If you've ever worked with RxJava, you may have encountered crashes due to null items or other issues, and seen a cryptic stack trace that due to the asynchronous nature of Rx, doesn't really give you any clues as to which observable instance actually emitted the error - only showing you that RxJava threw some kind of internal exception.
Well, I have good news for you - there's a library that can help make it easier to identify the source of these issues, and it's called RxDogTag!
https://github.com/uber/RxDogTag
This library works by making use of an RxJavaPlugin to help generate more helpful stack traces that identify the observable that was responsible for the crash!
There's just one thing to note - this only works if that subscription doesn't have its own custom onError()
handler. In my experience, I've found that it's generally good practice to always implement an onError()
handler to avoid exceptions bubbling all the way up to the top of your application, but there may be some cases where that's not a desired behavior/paradigm.
Either way, if you're frustrated/stuck trying to figure out a non-descriptive Rx crash stack trace, consider giving RxDogTag a try!
And, check out this other article which was how I learned about it initially: https://www.bugsnag.com/blog/improving-rxjava-stack-traces-with-rxdogtag
I hope you learned something that helps you more quickly identify RxJava crashes in the future! What strategies does your team use for handling RxJava errors? Let me know in the comments below! And, please follow me on Medium if you're interested in being notified of future tidbits.
Interested in joining the awesome team here at Intrepid? We're hiring!
This tidbit was originally discovered on December 20, 2019.
Top comments (0)