-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathFailureLoggingProvider.kt
More file actions
46 lines (40 loc) · 1.36 KB
/
FailureLoggingProvider.kt
File metadata and controls
46 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.kaspersky.kaspresso.failure
import android.view.View
import org.hamcrest.Matcher
/**
* An interface to provide the logging failures functionality.
*/
interface FailureLoggingProvider<Interaction> {
/**
* Invokes the given [action] and logs if it fails.
*
* @param action the action to invoke.
*
* @return the result of the [action] invocation.
*/
fun <T> withLoggingOnFailure(interaction: Interaction?, action: () -> T): T
/**
* Logs the [error]'s stacktrace.
*
* @param error the error to get stacktrace from.
*/
fun logStackTrace(interaction: Interaction?, error: Throwable)
/**
* Logs the [error] description got by [viewMatcher] and throws the [error].
*
* @param error the error to be described.
* @param viewMatcher the view matcher to get description from.
*/
fun logDescriptionAndThrow(error: Throwable?, viewMatcher: Matcher<View>?)
}
/**
* The function to call [FailureLoggingProvider.withLoggingOnFailure] with null-safety.
*
* @param action the action to invoke.
*
* @return the result of the [action] invocation.
*/
internal fun <Interaction, T> FailureLoggingProvider<Interaction>?.withLoggingOnFailureIfNotNull(
interaction: Interaction?,
action: () -> T
): T = if (this != null) withLoggingOnFailure(interaction, action) else action.invoke()