Skip to content

Commit

Permalink
Added error message with occurred exception info while saving by #1605
Browse files Browse the repository at this point in the history
                                                                 Open
  • Loading branch information
T8RIN committed Jan 20, 2025
1 parent 9c98d8b commit 04a37e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ sealed class SaveResult(
val isOverwritten: Boolean = false,
) : SaveResult(savingPath)

sealed class Error : SaveResult("") {
data object MissingPermissions : Error()
data class Exception(val throwable: Throwable) : Error()
sealed class Error(open val throwable: Throwable) : SaveResult("") {
data object MissingPermissions : Error(IllegalAccessException("MissingPermissions"))
data class Exception(
override val throwable: Throwable
) : Error(throwable)
}

fun onSuccess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ internal fun Activity.parseSaveResults(
} else if (failed < done) {
essentials.showConfetti()
val saveResult = results.firstOrNull { it is SaveResult.Success } as? SaveResult.Success
val errorSaveResult = results.firstOrNull { it is SaveResult.Error } as? SaveResult.Error
essentials.showToast(
message = saveResult?.message
?: getString(
Expand All @@ -141,11 +142,25 @@ internal fun Activity.parseSaveResults(
icon = Icons.Rounded.ErrorOutline,
duration = ToastDuration.Long
)
essentials.showToast(
message = getString(
R.string.smth_went_wrong,
errorSaveResult?.throwable?.localizedMessage ?: ""
)
)
} else {
val errorSaveResult = results.firstOrNull { it is SaveResult.Error } as? SaveResult.Error

essentials.showToast(
message = getString(R.string.failed_to_save, failed),
icon = Icons.Rounded.ErrorOutline,
duration = ToastDuration.Long
)
essentials.showToast(
message = getString(
R.string.smth_went_wrong,
errorSaveResult?.throwable?.localizedMessage ?: ""
)
)
}
}

0 comments on commit 04a37e8

Please sign in to comment.