Skip to content

Commit

Permalink
1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusMcCloud committed Jun 11, 2024
1 parent d813042 commit 0035549
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
## 1.6.1
- add missing `catching` variant

## NEXT
## 1.6.2
- `wrapping` function, which wraps any exception as the specified type
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.stability.nowarn=true
kotlin.native.ignoreDisabledTargets=true

artifactVersion = 1.6.2-SNAPSHOT
artifactVersion = 1.6.2
27 changes: 16 additions & 11 deletions src/commonMain/kotlin/at/asitplus/KmmResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package at.asitplus

import arrow.core.nonFatalOrThrow
import at.asitplus.KmmResult.Companion.wrap
import kotlin.experimental.ExperimentalObjCRefinement
import kotlin.jvm.JvmStatic
import kotlin.native.HiddenFromObjC
Expand Down Expand Up @@ -236,14 +235,17 @@ inline fun <T, R> T.catching(block: T.() -> R): KmmResult<R> {
*
* Usage: `wrapping(asA = ::ThrowableType) { block }`.
*/
inline fun <reified E: Throwable, R> wrapping(asA: (String?, Throwable)->E, block: ()->R): KmmResult<R> {
@Suppress("TooGenericExceptionCaught")
inline fun <reified E : Throwable, R> wrapping(asA: (String?, Throwable) -> E, block: () -> R): KmmResult<R> {
return try {
KmmResult.success(block())
} catch (e: Throwable) {
KmmResult.failure(when (e.nonFatalOrThrow()) {
is E -> e
else -> asA(e.message, e)
})
KmmResult.failure(
when (e.nonFatalOrThrow()) {
is E -> e
else -> asA(e.message, e)
}
)
}
}

Expand All @@ -253,13 +255,16 @@ inline fun <reified E: Throwable, R> wrapping(asA: (String?, Throwable)->E, bloc
*
* Usage: `wrapping(asA = ::ThrowableType) { block }`.
*/
inline fun <reified E: Throwable, T, R> T.wrapping(asA: (String?, Throwable)->E, block: T.()->R): KmmResult<R> {
@Suppress("TooGenericExceptionCaught")
inline fun <reified E : Throwable, T, R> T.wrapping(asA: (String?, Throwable) -> E, block: T.() -> R): KmmResult<R> {
return try {
KmmResult.success(block())
} catch (e: Throwable) {
KmmResult.failure(when (e.nonFatalOrThrow()) {
is E -> e
else -> asA(e.message, e)
})
KmmResult.failure(
when (e.nonFatalOrThrow()) {
is E -> e
else -> asA(e.message, e)
}
)
}
}

0 comments on commit 0035549

Please sign in to comment.