From 5f675d9f67dcc550733bb6e08e53cef6c0727614 Mon Sep 17 00:00:00 2001 From: Laurent Date: Sun, 28 Feb 2021 14:11:44 +0100 Subject: [PATCH] Adds logging when a crash occurs --- .../handhistory/model/ComputedAction.kt | 2 ++ .../handhistory/model/EditorViewModel.kt | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt index 4c1072d1..04765ba7 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt @@ -290,4 +290,6 @@ class ComputedAction(var manager: ActionManager, override val positionIndex: Int get() { return this.action.position } + val logRepresentation: String = "${this.action.type}, ${this.position}, ${this.action.amount}" + } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt index 92bb224b..84824b06 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt @@ -26,9 +26,11 @@ import net.pokeranalytics.android.ui.modules.handhistory.views.CardCentralizer import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor import net.pokeranalytics.android.ui.view.rows.CustomizableRowRepresentable +import net.pokeranalytics.android.util.CrashLogging import net.pokeranalytics.android.util.extensions.findById import net.pokeranalytics.android.util.extensions.formatted import timber.log.Timber +import java.lang.Exception import java.text.DecimalFormat import java.text.ParseException import kotlin.coroutines.CoroutineContext @@ -543,17 +545,24 @@ class EditorViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer return } - when (val row = this.rowRepresentables[this.currentSelection.index]) { - is ComputedAction -> { - this.sortedActions.setAmount(this.actionIndexForSelection, amount) - } - is PlayerSetupRow -> { - row.setStack(amount) - this.sortedActions.updateRemainingStacksForPositions(listOf(row.positionIndex)) + try { // can crash in setAmount for example + when (val row = this.rowRepresentables[this.currentSelection.index]) { + is ComputedAction -> { + this.sortedActions.setAmount(this.actionIndexForSelection, amount) + } + is PlayerSetupRow -> { + row.setStack(amount) + this.sortedActions.updateRemainingStacksForPositions(listOf(row.positionIndex)) + } + else -> {} } - else -> {} + } catch (e: Exception) { + val actions = this.sortedActions.joinToString("\n") { it.logRepresentation } + CrashLogging.log(actions) + throw e } + this.currentAmount = null }