Skip to content

Commit

Permalink
ISSUE-639: Attach both stack traces - original error's one and ours
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikitae57 committed Aug 26, 2024
1 parent fee4923 commit 9437101
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FailureLoggingProviderImpl(
error?.let { " because of ${error.javaClass.simpleName}" }
)

error?.let { throw it.describedWith(viewMatcher) }
error?.let { throw describeError(it, viewMatcher) }
}

/**
Expand All @@ -76,28 +76,27 @@ class FailureLoggingProviderImpl(
*
* @return transformed [error].
*/
private fun Throwable.describedWith(viewMatcher: Matcher<View>?): Throwable {
val newError = when {
this is PerformException -> {
private fun describeError(originalError: Throwable, viewMatcher: Matcher<View>?): Throwable {
return when {
originalError is PerformException -> {
PerformException.Builder()
.from(this)
.from(originalError)
.apply { viewMatcher?.let { withViewDescription(it.toString()) } }
.build()
.apply { addSuppressed(originalError) }
}
this is AssertionError -> {
AssertionFailedError(message).initCause(this)
originalError is AssertionError -> {
AssertionFailedError(originalError.message)
.initCause(originalError)
.apply { addSuppressed(originalError) }
}
isWebViewException(this) -> {
isWebViewException(originalError) -> {
val message = StringBuilder("Failed to interact with web view! Usually it means that desired element is not found or JavaScript is disabled in web view")
viewMatcher?.let { message.append("\nView description: ${it.describe()}") }
RuntimeException(message.toString())
RuntimeException(message.toString()).apply { addSuppressed(originalError) }
}
else -> this
else -> originalError.apply { addSuppressed(RuntimeException()) }
}
newError.stackTrace = Thread.currentThread().stackTrace
newError.addSuppressed(this)

return newError
}

private fun isWebViewException(throwable: Throwable): Boolean {
Expand Down

0 comments on commit 9437101

Please sign in to comment.