mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-06-30 15:15:02 +00:00
Compare commits
2 Commits
0.26.9
...
5d922346b5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d922346b5 | ||
| 52c4867468 |
@@ -1,10 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## 0.26.9
|
||||
|
||||
* `Coroutines`:
|
||||
* `runCatchingLogging` updated to rethrow `CancellationException` and log other exceptions
|
||||
|
||||
## 0.26.8
|
||||
|
||||
* `Versions`:
|
||||
|
||||
@@ -2,27 +2,11 @@ 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 {
|
||||
when (it) {
|
||||
is CancellationException -> throw it
|
||||
else -> logger.e(it) { errorMessageBuilder(it) }
|
||||
}
|
||||
logger.e(it) { errorMessageBuilder(it) }
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.26.9
|
||||
version=0.26.8
|
||||
android_code_version=307
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[versions]
|
||||
|
||||
kt = "2.2.21"
|
||||
kt = "2.3.0"
|
||||
kt-serialization = "1.9.0"
|
||||
kt-coroutines = "1.10.2"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user