https://kotlinlang.org logo
#coroutines
Title
# coroutines
k

Kulwinder Singh

01/05/2019, 8:01 AM
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

sashjakk

01/05/2019, 8:07 AM
Had something similar, and if I remember correctly solved it by catching
Throwable
instead of
Exception
k

Kulwinder Singh

01/05/2019, 8:12 AM
i have tried to replace it with
Throwable
but still app is crashing
d

Dico

01/05/2019, 8:37 AM
Do you have a stacktrace
k

Kulwinder Singh

01/05/2019, 9:14 AM
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

Dico

01/05/2019, 9:20 AM
I don't think this exception is related to the code you've shown us. Wouldn't you agree?
k

Kulwinder Singh

01/05/2019, 9:21 AM
but my Question is that
catch
block is not catching this exception
d

Dico

01/05/2019, 9:23 AM
Then maybe it's
result.result
throwing it when it's not successful.
You should try reversing the two conditions
k

Kulwinder Singh

01/05/2019, 10:04 AM
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

louiscad

06/03/2019, 7:56 AM
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
2 Views