Kamel-Media / Kamel

Kotlin asynchronous media loading and caching library for Compose.
Apache License 2.0
595 stars 23 forks source link

Crash with try/catch in loadImage*Resource #17

Closed Syer10 closed 2 years ago

Syer10 commented 2 years ago

If a operation is cancelled then it crashes the whole application. I can fix this in a PR pretty easily, so I will submit one soon.

java.lang.IllegalStateException: Flow exception transparency is violated:
    Previous 'emit' call has thrown exception kotlinx.coroutines.JobCancellationException: ScopeCoroutine is cancelling; job=ScopeCoroutine{Cancelled}@611efa09, but then emission attempt of value 'Failure(exception=io.ktor.utils.io.charsets.MalformedInputException: Input length = 1)' has been detected.
    Emissions from 'catch' blocks are prohibited in order to avoid unspecified behaviour, 'Flow.catch' operator can be used instead.
    For a more detailed explanation, please refer to Flow documentation.
    at kotlinx.coroutines.flow.internal.SafeCollector.exceptionTransparencyViolated(SafeCollector.kt:123) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.flow.internal.SafeCollector.checkContext(SafeCollector.kt:86) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.flow.internal.SafeCollector.emit(SafeCollector.kt:74) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.flow.internal.SafeCollector.emit(SafeCollector.kt:59) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at io.kamel.core.ImageLoadingKt$loadImageBitmapResource$1.invokeSuspend(ImageLoading.kt:38) ~[kamel-core-jvm-0.3.0-2477871edd7fe8212ada30a4ce4fd246.jar:?]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.6.10-c8ad75ca9e878d58128a377dded62d32.jar:1.6.10-release-923(1.6.10)]
    at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:33) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) ~[kotlin-stdlib-1.6.10-c8ad75ca9e878d58128a377dded62d32.jar:1.6.10-release-923(1.6.10)]
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:39) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665) ~[kotlinx-coroutines-core-jvm-1.6.0-1be8331acfc1add3a0362630f747944e.jar:?]