|
@@ -63,19 +63,19 @@ class ExceptionHandler(
|
|
private fun formatException(thread: Thread, exception: Throwable): String {
|
|
private fun formatException(thread: Thread, exception: Throwable): String {
|
|
fun formatExceptionRecursive(thread: Thread, exception: Throwable, count: Int = 0): String {
|
|
fun formatExceptionRecursive(thread: Thread, exception: Throwable, count: Int = 0): String {
|
|
if (count > EXCEPTION_FORMAT_MAX_RECURSIVITY) {
|
|
if (count > EXCEPTION_FORMAT_MAX_RECURSIVITY) {
|
|
- return " Max number of recursive exception causes exceeded!"
|
|
|
|
|
|
+ return "Max number of recursive exception causes exceeded!"
|
|
}
|
|
}
|
|
// print exception
|
|
// print exception
|
|
val stringBuilder = StringBuilder()
|
|
val stringBuilder = StringBuilder()
|
|
val stackTrace = exception.stackTrace
|
|
val stackTrace = exception.stackTrace
|
|
- stringBuilder.appendLine(" Exception in thread \"${thread.name}\" $exception")
|
|
|
|
|
|
+ stringBuilder.appendLine("Exception in thread \"${thread.name}\" $exception")
|
|
// print available stacktrace
|
|
// print available stacktrace
|
|
for (element in stackTrace) {
|
|
for (element in stackTrace) {
|
|
- stringBuilder.appendLine(" at $element")
|
|
|
|
|
|
+ stringBuilder.appendLine(" at $element")
|
|
}
|
|
}
|
|
// print cause recursively
|
|
// print cause recursively
|
|
exception.cause?.let {
|
|
exception.cause?.let {
|
|
- stringBuilder.append(" Caused by: ")
|
|
|
|
|
|
+ stringBuilder.append("Caused by: ")
|
|
stringBuilder.append(formatExceptionRecursive(thread, it, count + 1))
|
|
stringBuilder.append(formatExceptionRecursive(thread, it, count + 1))
|
|
}
|
|
}
|
|
return stringBuilder.toString()
|
|
return stringBuilder.toString()
|
|
@@ -87,52 +87,33 @@ class ExceptionHandler(
|
|
private fun generateErrorReport(stackTrace: String): String {
|
|
private fun generateErrorReport(stackTrace: String): String {
|
|
val buildNumber = context.resources.getString(R.string.buildNumber)
|
|
val buildNumber = context.resources.getString(R.string.buildNumber)
|
|
|
|
|
|
- var buildNumberString = ""
|
|
|
|
- if (buildNumber.isNotEmpty()) {
|
|
|
|
- buildNumberString = " (build #$buildNumber)"
|
|
|
|
|
|
+ val buildNumberString = when {
|
|
|
|
+ buildNumber.isNotEmpty() -> " (build #$buildNumber)"
|
|
|
|
+ else -> ""
|
|
}
|
|
}
|
|
|
|
|
|
- return "************ CAUSE OF ERROR ************\n\n" +
|
|
|
|
- stackTrace +
|
|
|
|
- "\n************ APP INFORMATION ************" +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "ID: " +
|
|
|
|
- BuildConfig.APPLICATION_ID +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Version: " +
|
|
|
|
- BuildConfig.VERSION_CODE +
|
|
|
|
- buildNumberString +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Build flavor: " +
|
|
|
|
- BuildConfig.FLAVOR +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "\n************ DEVICE INFORMATION ************" +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Brand: " +
|
|
|
|
- Build.BRAND +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Device: " +
|
|
|
|
- Build.DEVICE +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Model: " +
|
|
|
|
- Build.MODEL +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Id: " +
|
|
|
|
- Build.ID +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Product: " +
|
|
|
|
- Build.PRODUCT +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "\n************ FIRMWARE ************" +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "SDK: " +
|
|
|
|
- Build.VERSION.SDK_INT +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Release: " +
|
|
|
|
- Build.VERSION.RELEASE +
|
|
|
|
- LINE_SEPARATOR +
|
|
|
|
- "Incremental: " +
|
|
|
|
- Build.VERSION.INCREMENTAL +
|
|
|
|
- LINE_SEPARATOR
|
|
|
|
|
|
+ return """
|
|
|
|
+ |### Cause of error
|
|
|
|
+ |```java
|
|
|
|
+ ${stackTrace.prependIndent("|")}
|
|
|
|
+ |```
|
|
|
|
+ |
|
|
|
|
+ |### App information
|
|
|
|
+ |* ID: `${BuildConfig.APPLICATION_ID}`
|
|
|
|
+ |* Version: `${BuildConfig.VERSION_CODE}$buildNumberString`
|
|
|
|
+ |* Build flavor: `${BuildConfig.FLAVOR}`
|
|
|
|
+ |
|
|
|
|
+ |### Device information
|
|
|
|
+ |* Brand: `${Build.BRAND}`
|
|
|
|
+ |* Device: `${Build.DEVICE}`
|
|
|
|
+ |* Model: `${Build.MODEL}`
|
|
|
|
+ |* Id: `${Build.ID}`
|
|
|
|
+ |* Product: `${Build.PRODUCT}`
|
|
|
|
+ |
|
|
|
|
+ |### Firmware
|
|
|
|
+ |* SDK: `${Build.VERSION.SDK_INT}`
|
|
|
|
+ |* Release: `${Build.VERSION.RELEASE}`
|
|
|
|
+ |* Incremental: `${Build.VERSION.INCREMENTAL}`
|
|
|
|
+ """.trimMargin("|")
|
|
}
|
|
}
|
|
}
|
|
}
|