:wave: Need an advice about finding causes of this...
# coroutines
e
👋 Need an advice about finding causes of this error crash in Android app:
Copy code
kotlinx.coroutines.JobCancellationException: StandaloneCoroutine was cancelled
It has no stacktrace (due to https://github.com/Kotlin/kotlinx.coroutines/issues/1866). The only case that I was able to reproduce is when you throw this exception outside of coroutines. Any ideas?
s
You should expect to see this exception when using coroutines. It indicates normal cancellation of a job and isn’t an error. Generally, don’t catch it and don’t log it.
e
This is a crash or process, it’s obviously not catched or logged or throwed manually
s
There are places where cancellation exceptions can propagate into places where they shouldn’t… examples I can think of include: • Calling
await
on a cancelled deferred • Calling
cancel()
on the current job, especially inside a coroutineScope or withContext block
If a cancellation exception is causing the app to crash, it suggests it’s propagating outside of the coroutine that was supposed to be cancelled 😞
e
especially inside a coroutineScope or withContext block
I couldn’t reproduce it manually inside any scope/coroutine. Any cancellation exception was swallowed silently as expected.
s
The simplest reproduction I know of is this:
Copy code
suspend fun main() = coroutineScope {
   cancel()
}
https://pl.kotl.in/69W7CAite I’m not familiar with Android so I’m not sure how I would repro it there
z
You could set an exception breakpoint for that exception type in the debugger to see the raw stack trace at least. Might be noisy tho
e
It works only if you can reproduce it think smart The thing is, we didn’t encounter this crash in debug builds yet.