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

ISSUE-639: Don't set stack trace #666

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all 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
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
Loading