Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cached error deserialisation where the Throwable has a cause #418

Merged
merged 11 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Bug fixes

* Fix cached error deserialisation where the Throwable has a cause
[#418](https://github.com/bugsnag/bugsnag-android/pull/418)

* Cache result of device root check
[#411](https://github.com/bugsnag/bugsnag-android/pull/411)

Expand Down
57 changes: 57 additions & 0 deletions sdk/src/androidTest/java/com/bugsnag/android/RxErrorTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.bugsnag.android

import android.support.test.InstrumentationRegistry
import com.bugsnag.android.BugsnagTestUtils.streamableToJsonArray
import com.bugsnag.android.test.R
import org.json.JSONObject
import org.junit.Assert.*

import org.junit.Test

import java.io.File
import java.io.FileOutputStream

class RxErrorTest {

@Test
fun loadRxError() {
val error = loadErrorFromFile()!!
val jsonArray = streamableToJsonArray(error.exceptions)

with(jsonArray) {
assertEquals(2, length())
validateRootThrowable(getJSONObject(0))
validateCauseThrowable(getJSONObject(1))
}
}

private fun validateRootThrowable(rootExc: JSONObject) {
assertEquals(
"io.reactivex.exceptions.OnErrorNotImplementedException",
rootExc.getString("errorClass")
)
assertEquals(
"The exception was not handled due to missing onError handler " +
"in the subscribe() method call. Further reading: https://github.com/ReactiveX/" +
"RxJava/wiki/Error-Handling | java.lang.RuntimeException: Whoops!",
rootExc.getString("message")
)
assertEquals("custom", rootExc.getString("type"))
assertEquals(32, rootExc.getJSONArray("stacktrace").length())
}

private fun validateCauseThrowable(causeExc: JSONObject) {
assertEquals("java.lang.RuntimeException", causeExc.getString("errorClass"))
assertEquals("Whoops!", causeExc.getString("message"))
assertEquals("custom", causeExc.getString("type"))
assertEquals(29, causeExc.getJSONArray("stacktrace").length())
}

private fun loadErrorFromFile(): Error? {
fractalwrench marked this conversation as resolved.
Show resolved Hide resolved
val input = InstrumentationRegistry.getContext().resources
.openRawResource(R.raw.rx_error)
val fixtureFile = File.createTempFile("rx_error", ".json")
input.copyTo(FileOutputStream(fixtureFile))
return ErrorReader.readError(Configuration("key"), fixtureFile)
}
}
Loading