Skip to content

Commit a408df4

Browse files
committed
fix DatabaseException on ios
1 parent 7ead0aa commit a408df4

File tree

2 files changed

+7
-7
lines changed
  • firebase-database/src
    • androidMain/kotlin/dev/gitlive/firebase/database
    • iosMain/kotlin/dev/gitlive/firebase/database

2 files changed

+7
-7
lines changed

firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ suspend fun <T> Task<T>.awaitWhileOnline(): T = coroutineScope {
4444

4545
select<T> {
4646
asDeferred().onAwait { it.also { notConnected.cancel() } }
47-
notConnected.onReceive { throw DatabaseException("Database not connected") }
47+
notConnected.onReceive { throw DatabaseException("Database not connected", null) }
4848
}
4949
}
5050

firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ actual open class Query internal constructor(
107107
withBlock = { snapShot ->
108108
safeOffer(DataSnapshot(snapShot!!))
109109
}
110-
) { close(DatabaseException(it.toString())) }
110+
) { close(DatabaseException(it.toString(), null)) }
111111
awaitClose { ios.removeObserverWithHandle(handle) }
112112
}
113113

@@ -118,7 +118,7 @@ actual open class Query internal constructor(
118118
andPreviousSiblingKeyWithBlock = { snapShot, key ->
119119
safeOffer(ChildEvent(DataSnapshot(snapShot!!), type, key))
120120
}
121-
) { close(DatabaseException(it.toString())) }
121+
) { close(DatabaseException(it.toString(), null)) }
122122
}
123123
awaitClose {
124124
handles.forEach { ios.removeObserverWithHandle(it) }
@@ -201,15 +201,15 @@ actual class OnDisconnect internal constructor(
201201
}
202202
}
203203

204-
actual class DatabaseException(message: String) : RuntimeException(message)
204+
actual class DatabaseException(message: String?, cause: Throwable?) : RuntimeException(message, cause)
205205

206206
private suspend inline fun <T, reified R> T.awaitResult(whileOnline: Boolean, function: T.(callback: (NSError?, R?) -> Unit) -> Unit): R {
207207
val job = CompletableDeferred<R?>()
208208
function { error, result ->
209209
if(error == null) {
210210
job.complete(result)
211211
} else {
212-
job.completeExceptionally(DatabaseException(error.toString()))
212+
job.completeExceptionally(DatabaseException(error.toString(), null))
213213
}
214214
}
215215
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
221221
if(error == null) {
222222
job.complete(Unit)
223223
} else {
224-
job.completeExceptionally(DatabaseException(error.toString()))
224+
job.completeExceptionally(DatabaseException(error.toString(), null))
225225
}
226226
}
227227
job.run { if(whileOnline) awaitWhileOnline() else await() }
@@ -238,6 +238,6 @@ suspend fun <T> CompletableDeferred<T>.awaitWhileOnline(): T = coroutineScope {
238238

239239
select<T> {
240240
onAwait { it.also { notConnected.cancel() } }
241-
notConnected.onReceive { throw DatabaseException("Database not connected") }
241+
notConnected.onReceive { throw DatabaseException("Database not connected", null) }
242242
}
243243
}

0 commit comments

Comments
 (0)