Add LocalOnlyException
This is intended to enable local logging of some exceptions for debugging purposes without overrunning the remote crash reporter with issues that can't really be actioned upon
This commit is contained in:
parent
b1e698c9c9
commit
98688cbc3b
2 changed files with 13 additions and 3 deletions
|
@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.lifecycle.viewmodel.CreationExtras
|
import androidx.lifecycle.viewmodel.CreationExtras
|
||||||
|
import com.wbrawner.simplemarkdown.core.LocalOnlyException
|
||||||
import com.wbrawner.simplemarkdown.utility.FileHelper
|
import com.wbrawner.simplemarkdown.utility.FileHelper
|
||||||
import com.wbrawner.simplemarkdown.utility.Preference
|
import com.wbrawner.simplemarkdown.utility.Preference
|
||||||
import com.wbrawner.simplemarkdown.utility.PreferenceHelper
|
import com.wbrawner.simplemarkdown.utility.PreferenceHelper
|
||||||
|
@ -109,7 +110,7 @@ class MarkdownViewModel(
|
||||||
preferenceHelper[Preference.AUTOSAVE_URI] = actualLoadPath
|
preferenceHelper[Preference.AUTOSAVE_URI] = actualLoadPath
|
||||||
} ?: throw IllegalStateException("Opened file was null")
|
} ?: throw IllegalStateException("Opened file was null")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Failed to open file at path: $actualLoadPath")
|
Timber.e(LocalOnlyException(e), "Failed to open file at path: $actualLoadPath")
|
||||||
_state.value = _state.value.copy(
|
_state.value = _state.value.copy(
|
||||||
alert = AlertDialogModel(
|
alert = AlertDialogModel(
|
||||||
text = ParameterizedText(R.string.file_load_error),
|
text = ParameterizedText(R.string.file_load_error),
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.wbrawner.simplemarkdown.core
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import org.acra.ACRA
|
|
||||||
import org.acra.config.httpSender
|
import org.acra.config.httpSender
|
||||||
import org.acra.data.StringFormat
|
import org.acra.data.StringFormat
|
||||||
import org.acra.ktx.initAcra
|
import org.acra.ktx.initAcra
|
||||||
|
@ -13,7 +12,9 @@ import timber.log.Timber
|
||||||
class ErrorReporterTree private constructor(): Timber.Tree() {
|
class ErrorReporterTree private constructor(): Timber.Tree() {
|
||||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||||
if (priority != Log.ERROR) return
|
if (priority != Log.ERROR) return
|
||||||
t?.sendSilentlyWithAcra()
|
if (t !is LocalOnlyException) {
|
||||||
|
t?.sendSilentlyWithAcra()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -24,6 +25,14 @@ class ErrorReporterTree private constructor(): Timber.Tree() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception wrapper that prevents exceptions from being sent to an error reporter. Useful for
|
||||||
|
* logging things like IOExceptions that are useful to see locally but not so helpful if reported
|
||||||
|
*/
|
||||||
|
class LocalOnlyException(override val message: String?, override val cause: Throwable): Exception(message, cause) {
|
||||||
|
constructor(cause: Throwable): this(null, cause)
|
||||||
|
}
|
||||||
|
|
||||||
private fun Application.createErrorReporterTree() {
|
private fun Application.createErrorReporterTree() {
|
||||||
initAcra {
|
initAcra {
|
||||||
reportFormat = StringFormat.JSON
|
reportFormat = StringFormat.JSON
|
||||||
|
|
Loading…
Reference in a new issue