Coroutine exception logging in context

This commit is contained in:
Alexander Nozik 2024-08-03 10:04:24 +03:00
parent 904262a22a
commit e5902c0bfe
2 changed files with 5 additions and 1 deletions

View File

@ -3,6 +3,7 @@
## Unreleased
### Added
- Coroutine exception logging in context
### Changed
- Simplify inheritance logic in `MutableTypedMeta`

View File

@ -1,5 +1,6 @@
package space.kscience.dataforge.context
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
@ -67,7 +68,9 @@ public open class Context internal constructor(
override val coroutineContext: CoroutineContext by lazy {
(parent ?: Global).coroutineContext.let { parenContext ->
parenContext + coroutineContext + SupervisorJob(parenContext[Job])
parenContext + coroutineContext + SupervisorJob(parenContext[Job]) + CoroutineExceptionHandler { _, throwable ->
logger.error(throwable) { "Exception in context $name" }
}
}
}