Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/copyright/IceRock.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ allprojects {
project build.gradle
```groovy
dependencies {
commonMainApi("dev.icerock.moko:errors:0.5.1")
commonMainApi("dev.icerock.moko:errors:0.6.0")
}
```

Expand Down
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ buildscript {
repositories {
mavenCentral()
google()

gradlePluginPortal()
}

dependencies {
classpath("dev.icerock.moko:resources-generator:0.16.0")

classpath(":errors-build-logic")
classpath(libs.kotlinGradlePlugin)
classpath(libs.androidGradlePlugin)
classpath(libs.mokoGradlePlugin)
classpath(libs.mokoResourcesGradlePlugin)
}
}

apply(plugin = "dev.icerock.moko.gradle.publication.nexus")

allprojects {

allprojects {
Expand Down
17 changes: 0 additions & 17 deletions errors-build-logic/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions errors-build-logic/src/main/kotlin/detekt-convention.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 6 additions & 5 deletions errors/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
*/

plugins {
id("multiplatform-library-convention")
id("dev.icerock.moko.gradle.multiplatform.mobile")
id("kotlin-parcelize")
id("dev.icerock.mobile.multiplatform-resources")
id("detekt-convention")
id("publication-convention")
id("dev.icerock.moko.gradle.detekt")
id("dev.icerock.moko.gradle.publication")
id("dev.icerock.moko.gradle.stub.javadoc")
}

group = "dev.icerock.moko"
Expand All @@ -16,8 +17,8 @@ version = libs.versions.mokoErrorsVersion.get()
dependencies {
commonMainImplementation(libs.coroutines)

"androidMainImplementation"(libs.appCompat)
"androidMainImplementation"(libs.material)
androidMainImplementation(libs.appCompat)
androidMainImplementation(libs.material)

commonMainImplementation(libs.mokoMvvmCore)
commonMainApi(libs.mokoResources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import android.os.Parcelable
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import dev.icerock.moko.errors.R
import kotlinx.android.parcel.Parcelize
import java.lang.IllegalStateException
import kotlinx.parcelize.Parcelize

class AlertDialogFragment : DialogFragment() {

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val settings: DialogSettings = arguments?.getParcelable<DialogSettings>(ARGS_KEY)
val settings: DialogSettings = arguments?.getParcelable(ARGS_KEY)
?: DialogSettings(
title = getString(R.string.moko_errors_presenters_alertDialogTitle),
positiveButtonText = getString(R.string.moko_errors_presenters_alertPositiveButton),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ internal class PresenterExceptionHandler<T : Any>(
private val errorPresenter: ErrorPresenter<T>,
private val errorEventsDispatcher: EventsDispatcher<ErrorEventListener<T>>,
private val onCatch: ((Throwable) -> Unit)? = null
) : ExceptionHandlerBinder by ExceptionHandlerBinderImpl<T>(
errorPresenter,
errorEventsDispatcher
), ExceptionHandler {
) : ExceptionHandlerBinder by ExceptionHandlerBinderImpl(errorPresenter, errorEventsDispatcher),
ExceptionHandler {

override fun <R> handle(block: suspend () -> R): ExceptionHandlerContext<R> {
return ExceptionHandlerContext(exceptionMapper, errorEventsDispatcher, onCatch, block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ object ExceptionMappersStorage {
if (!mappersMap.containsKey(resultClass)) {
mappersMap[resultClass] = mutableMapOf()
}
mappersMap.get(resultClass)?.put(exceptionClass, mapper as ThrowableMapper)
@Suppress("UNCHECKED_CAST")
mappersMap[resultClass]?.put(exceptionClass, mapper as ThrowableMapper)
return this
}

Expand All @@ -50,7 +51,7 @@ object ExceptionMappersStorage {
if (!conditionMappers.containsKey(resultClass)) {
conditionMappers[resultClass] = mutableListOf()
}
conditionMappers.get(resultClass)?.add(conditionPair)
conditionMappers[resultClass]?.add(conditionPair)
return this
}

Expand Down Expand Up @@ -93,10 +94,11 @@ object ExceptionMappersStorage {
throwable: E,
exceptionClass: KClass<out E>
): ((E) -> T)? {
val mapper = conditionMappers.get(resultClass)
@Suppress("UNCHECKED_CAST")
val mapper = conditionMappers[resultClass]
?.find { it.condition(throwable) }
?.mapper as? ((E) -> T)
?: mappersMap.get(resultClass)?.get(exceptionClass) as? ((E) -> T)
?: mappersMap[resultClass]?.get(exceptionClass) as? ((E) -> T)

return if (mapper == null && throwable !is Exception) {
throw throwable
Expand Down Expand Up @@ -138,6 +140,7 @@ object ExceptionMappersStorage {
* exception will be thrown.
*/
fun <T : Any> getFallbackValue(clazz: KClass<T>): T {
@Suppress("UNCHECKED_CAST")
return fallbackValuesMap[clazz] as? T
?: throw FallbackValueNotFoundException(clazz)
}
Expand All @@ -160,15 +163,19 @@ object ExceptionMappersStorage {
}
}

/**
* Factory method that creates mappers (Throwable) -> T with a registered fallback value for
* class [T].
*/
inline fun <E : Throwable, reified T : Any> throwableMapper(): (e: E) -> T {
return ExceptionMappersStorage.throwableMapper(T::class)
return dev.icerock.moko.errors.mappers.throwableMapper()
}
}

/**
* Factory method that creates mappers (Throwable) -> T with a registered fallback value for
* class [T].
*/
inline fun <E : Throwable, reified T : Any> throwableMapper(): (e: E) -> T {
return ExceptionMappersStorage.throwableMapper(T::class)
}

/**
* Factory method that allows getting exception description
*/
Expand Down
Loading