secant-android-wallet/crash-lib/src/jvmMain/kotlin/co/electriccoin/zcash/crash/ReportedExceptionExt.kt

30 lines
932 B
Kotlin

@file:Suppress("ktlint:filename")
package co.electriccoin.zcash.crash
import kotlinx.datetime.Instant
import java.io.File
fun ReportedException.Companion.new(file: File): ReportedException? {
// Exclude temp files
if (file.extension == ExceptionPath.TYPE) {
val name: String = file.nameWithoutExtension
val splitName = name.split(ExceptionPath.SEPARATOR)
val epochSeconds = splitName.firstOrNull()?.toLongOrNull()
val classNameString = splitName.getOrNull(2)
val isUncaught = splitName.lastOrNull()?.toBoolean()
if (null != epochSeconds && null != classNameString && null != isUncaught) {
return ReportedException(
filePath = file.path,
exceptionClassName = classNameString,
isUncaught = isUncaught,
time = Instant.fromEpochSeconds(epochSeconds)
)
}
}
return null
}