Add readable error messages
This commit is contained in:
parent
c4c8a29d62
commit
731d6be5f0
4 changed files with 33 additions and 23 deletions
|
@ -17,6 +17,7 @@ import eu.m724.pojavbackup.R
|
|||
import eu.m724.pojavbackup.core.backup.Backup.BackupStatus
|
||||
import eu.m724.pojavbackup.core.backup.exception.BackupFailedException
|
||||
import eu.m724.pojavbackup.core.backup.exception.BackupOfWorldException
|
||||
import eu.m724.pojavbackup.core.backup.exception.MisconfiguredException
|
||||
import eu.m724.pojavbackup.core.data.GameDataRepository
|
||||
import eu.m724.pojavbackup.core.data.World
|
||||
import eu.m724.pojavbackup.core.datastore.SettingsRepository
|
||||
|
@ -48,9 +49,15 @@ class BackupWorker @AssistedInject constructor(
|
|||
backupRepository.completeBackup(backup, BackupStatus.SUCCESS)
|
||||
return Result.success(statusData(backup.id, "Backup completed successfully"))
|
||||
} catch (cause: Throwable) {
|
||||
val status = if (cause is MisconfiguredException) {
|
||||
cause.message!!
|
||||
} else {
|
||||
"Backup failed"
|
||||
}
|
||||
|
||||
val data = statusData(
|
||||
uuid = backup.id,
|
||||
status = "Backup failed",
|
||||
status = status,
|
||||
error = BackupFailedException(backup, cause)
|
||||
)
|
||||
|
||||
|
@ -61,7 +68,18 @@ class BackupWorker @AssistedInject constructor(
|
|||
|
||||
private suspend fun doBackup(backup: Backup) {
|
||||
val settings = settingsRepository.settingsFlow.first()
|
||||
val sources = settings.sourcesList
|
||||
|
||||
val sources = settings.sourcesList.apply {
|
||||
if (isEmpty()) {
|
||||
throw MisconfiguredException("No sources configured")
|
||||
}
|
||||
}
|
||||
|
||||
val destinations = settings.destinationsList.apply {
|
||||
if (isEmpty()) {
|
||||
throw MisconfiguredException("No destinations configured")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO other source types support
|
||||
val worldIds = sources
|
||||
|
@ -69,7 +87,7 @@ class BackupWorker @AssistedInject constructor(
|
|||
.map { it.id }
|
||||
|
||||
// TODO multiple destinations support
|
||||
val destinationUri = settings.destinationsList.first().uri.toUri()
|
||||
val destinationUri = destinations.first().uri.toUri()
|
||||
val backupDirectory = createBackupDirectory(backup.id, destinationUri)
|
||||
|
||||
val documentFileCompressor = DocumentFileCompressor(
|
||||
|
|
|
@ -5,5 +5,4 @@ import eu.m724.pojavbackup.core.backup.Backup
|
|||
class BackupFailedException(
|
||||
backup: Backup,
|
||||
cause: Throwable
|
||||
) : BackupException(backup, cause) {
|
||||
}
|
||||
) : BackupException(backup, cause)
|
|
@ -0,0 +1,5 @@
|
|||
package eu.m724.pojavbackup.core.backup.exception
|
||||
|
||||
class MisconfiguredException(
|
||||
message: String,
|
||||
) : Exception(message)
|
|
@ -3,16 +3,16 @@ package eu.m724.pojavbackup.settings.screen.options
|
|||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.BasicAlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
|
@ -60,15 +60,13 @@ fun OptionsScreen(
|
|||
openAlertDialog.value -> {
|
||||
BasicAlertDialog(
|
||||
onDismissRequest = { openAlertDialog.value = false },
|
||||
modifier = Modifier.fillMaxSize().padding(16.dp),
|
||||
properties = DialogProperties(
|
||||
dialogContentTitle = "Stacktrace"
|
||||
)
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(300.dp)
|
||||
.padding(16.dp)
|
||||
Surface(
|
||||
modifier = Modifier.wrapContentWidth().wrapContentHeight()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
) {
|
||||
|
@ -92,14 +90,4 @@ fun OptionsScreen(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BasicAlertDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
modifier: Modifier,
|
||||
properties: DialogProperties,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue