mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-06-07 15:47:23 +00:00
Compare commits
3 Commits
5bb9a6041b
...
v0.26.9
| Author | SHA1 | Date | |
|---|---|---|---|
| abbc38a2c2 | |||
| 6e320ebcf8 | |||
| df95f78bb3 |
@@ -1,5 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## 0.26.9
|
||||
|
||||
* `Coroutines`:
|
||||
* `runCatchingLogging` updated to rethrow `CancellationException` and log other exceptions
|
||||
|
||||
## 0.26.8
|
||||
|
||||
* `Versions`:
|
||||
|
||||
@@ -2,11 +2,27 @@ package dev.inmo.micro_utils.coroutines
|
||||
|
||||
import dev.inmo.kslog.common.KSLog
|
||||
import dev.inmo.kslog.common.e
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
|
||||
/**
|
||||
* Executes the given [block] within a `runCatching` context and logs any exceptions that occur, excluding
|
||||
* `CancellationException` which is rethrown. This method simplifies error handling by automatically logging
|
||||
* the errors using the provided [logger].
|
||||
*
|
||||
* @param T The result type of the [block].
|
||||
* @param R The receiver type on which this function operates.
|
||||
* @param errorMessageBuilder A lambda to build the error log message. By default, it returns a generic error message.
|
||||
* @param logger The logging instance used for logging errors. Defaults to [KSLog].
|
||||
* @param block The code block to execute within the `runCatching` context.
|
||||
* @return A [Result] representing the outcome of executing the [block].
|
||||
*/
|
||||
inline fun <T, R> R.runCatchingLogging(
|
||||
noinline errorMessageBuilder: R.(Throwable) -> Any = { "Something web wrong" },
|
||||
logger: KSLog = KSLog,
|
||||
block: R.() -> T
|
||||
) = runCatching(block).onFailure {
|
||||
logger.e(it) { errorMessageBuilder(it) }
|
||||
when (it) {
|
||||
is CancellationException -> throw it
|
||||
else -> logger.e(it) { errorMessageBuilder(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.26.8
|
||||
version=0.26.9
|
||||
android_code_version=307
|
||||
|
||||
@@ -15,7 +15,7 @@ jb-exposed = "0.61.0"
|
||||
jb-dokka = "2.1.0"
|
||||
|
||||
# 3.51.0.0 contains bug, checking with ./gradlew :micro_utils.repos.exposed:jvmTest
|
||||
sqlite = "3.51.1.0"
|
||||
sqlite = "3.50.1.0"
|
||||
|
||||
korlibs = "5.4.0"
|
||||
uuid = "0.8.4"
|
||||
|
||||
Reference in New Issue
Block a user