Hi all, i have created `extension` function `await...
# coroutines
k
Hi all, i have created
extension
function
await
to get document from firestore database. But when i'm using it like below, exception is thrown and my crashes
s
Had something similar, and if I remember correctly solved it by catching
Throwable
instead of
Exception
k
i have tried to replace it with
Throwable
but still app is crashing
d
Do you have a stacktrace
k
Copy code
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
        at com.google.android.gms.tasks.zzu.getResult(Unknown Source:15)
        at com.arkatech.common.FirebaseKt$await$2$1.onComplete(firebase.kt:101)
        at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6501)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
d
I don't think this exception is related to the code you've shown us. Wouldn't you agree?
k
but my Question is that
catch
block is not catching this exception
d
Then maybe it's
result.result
throwing it when it's not successful.
You should try reversing the two conditions
k
Copy code
suspend fun <T> Task<T>.await(): T = suspendCancellableCoroutine { continuation ->
    this.addOnSuccessListener(continuation::resume)
            .addOnFailureListener { continuation.resumeWithException(it) }
            .addOnCanceledListener { continuation.cancel() }
}
Changing
await
to this worked
l
Hey @Kulwinder Singh, could you provide a reproducer in that issue I raised, in reply to last comment? https://github.com/Kotlin/kotlinx.coroutines/issues/1197#issuecomment-494425635