@@ -107,7 +107,7 @@ actual open class Query internal constructor(
107
107
withBlock = { snapShot ->
108
108
safeOffer(DataSnapshot (snapShot!! ))
109
109
}
110
- ) { close(DatabaseException (it.toString())) }
110
+ ) { close(DatabaseException (it.toString(), null )) }
111
111
awaitClose { ios.removeObserverWithHandle(handle) }
112
112
}
113
113
@@ -118,7 +118,7 @@ actual open class Query internal constructor(
118
118
andPreviousSiblingKeyWithBlock = { snapShot, key ->
119
119
safeOffer(ChildEvent (DataSnapshot (snapShot!! ), type, key))
120
120
}
121
- ) { close(DatabaseException (it.toString())) }
121
+ ) { close(DatabaseException (it.toString(), null )) }
122
122
}
123
123
awaitClose {
124
124
handles.forEach { ios.removeObserverWithHandle(it) }
@@ -201,15 +201,15 @@ actual class OnDisconnect internal constructor(
201
201
}
202
202
}
203
203
204
- actual class DatabaseException (message : String ) : RuntimeException(message)
204
+ actual class DatabaseException (message : String? , cause : Throwable ? ) : RuntimeException(message, cause )
205
205
206
206
private suspend inline fun <T , reified R > T.awaitResult (whileOnline : Boolean , function : T .(callback: (NSError ? , R ? ) -> Unit ) -> Unit ): R {
207
207
val job = CompletableDeferred <R ?>()
208
208
function { error, result ->
209
209
if (error == null ) {
210
210
job.complete(result)
211
211
} else {
212
- job.completeExceptionally(DatabaseException (error.toString()))
212
+ job.completeExceptionally(DatabaseException (error.toString(), null ))
213
213
}
214
214
}
215
215
return job.run { if (whileOnline) awaitWhileOnline() else await() } as R
@@ -221,7 +221,7 @@ suspend inline fun <T> T.await(whileOnline: Boolean, function: T.(callback: (NSE
221
221
if (error == null ) {
222
222
job.complete(Unit )
223
223
} else {
224
- job.completeExceptionally(DatabaseException (error.toString()))
224
+ job.completeExceptionally(DatabaseException (error.toString(), null ))
225
225
}
226
226
}
227
227
job.run { if (whileOnline) awaitWhileOnline() else await() }
@@ -238,6 +238,6 @@ suspend fun <T> CompletableDeferred<T>.awaitWhileOnline(): T = coroutineScope {
238
238
239
239
select<T > {
240
240
onAwait { it.also { notConnected.cancel() } }
241
- notConnected.onReceive { throw DatabaseException (" Database not connected" ) }
241
+ notConnected.onReceive { throw DatabaseException (" Database not connected" , null ) }
242
242
}
243
243
}
0 commit comments