33
44@file:Suppress(" NAME_SHADOWING" )
55
6- package uniffi.matrix_sdk ;
6+ package uniffi.matrix_sdk
77
88// Common helper code.
99//
@@ -235,7 +235,7 @@ internal open class UniffiRustCallStatus : Structure() {
235235 }
236236}
237237
238- class InternalException (message : String ) : Exception(message)
238+ class InternalException (message : String ) : kotlin. Exception(message)
239239
240240// Each top-level error class has a companion object that can lift the error from the call status's rust buffer
241241interface UniffiRustCallStatusErrorHandler <E > {
@@ -247,15 +247,15 @@ interface UniffiRustCallStatusErrorHandler<E> {
247247// synchronize itself
248248
249249// Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
250- private inline fun <U , E : Exception > uniffiRustCallWithError (errorHandler : UniffiRustCallStatusErrorHandler <E >, callback : (UniffiRustCallStatus ) -> U ): U {
251- var status = UniffiRustCallStatus ();
250+ private inline fun <U , E : kotlin. Exception > uniffiRustCallWithError (errorHandler : UniffiRustCallStatusErrorHandler <E >, callback : (UniffiRustCallStatus ) -> U ): U {
251+ var status = UniffiRustCallStatus ()
252252 val return_value = callback(status)
253253 uniffiCheckCallStatus(errorHandler, status)
254254 return return_value
255255}
256256
257257// Check UniffiRustCallStatus and throw an error if the call wasn't successful
258- private fun <E : Exception > uniffiCheckCallStatus (errorHandler : UniffiRustCallStatusErrorHandler <E >, status : UniffiRustCallStatus ) {
258+ private fun <E : kotlin. Exception > uniffiCheckCallStatus (errorHandler : UniffiRustCallStatusErrorHandler <E >, status : UniffiRustCallStatus ) {
259259 if (status.isSuccess()) {
260260 return
261261 } else if (status.isError()) {
@@ -284,7 +284,7 @@ object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<In
284284
285285// Call a rust function that returns a plain value
286286private inline fun <U > uniffiRustCall (callback : (UniffiRustCallStatus ) -> U ): U {
287- return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler , callback);
287+ return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler , callback)
288288}
289289
290290internal inline fun <T > uniffiTraitInterfaceCall (
@@ -294,7 +294,7 @@ internal inline fun<T> uniffiTraitInterfaceCall(
294294) {
295295 try {
296296 writeReturn(makeCall())
297- } catch (e: Exception ) {
297+ } catch (e: kotlin. Exception ) {
298298 callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
299299 callStatus.error_buf = FfiConverterString .lower(e.toString())
300300 }
@@ -308,7 +308,7 @@ internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
308308) {
309309 try {
310310 writeReturn(makeCall())
311- } catch (e: Exception ) {
311+ } catch (e: kotlin. Exception ) {
312312 if (e is E ) {
313313 callStatus.code = UNIFFI_CALL_ERROR
314314 callStatus.error_buf = lowerError(e)
@@ -1466,71 +1466,132 @@ public object FfiConverterTypePaginatorState: FfiConverterRustBuffer<PaginatorSt
14661466
14671467
14681468
1469+
1470+
14691471/* *
14701472 * The error type for failures while trying to log in a new device using a QR
14711473 * code.
14721474 */
1473-
1474- enum class QrCodeLoginError {
1475-
1475+ sealed class QrCodeLoginException (message : String ): kotlin.Exception(message) {
1476+
14761477 /* *
14771478 * An error happened while we were communicating with the OIDC provider.
14781479 */
1479- OIDC ,
1480+ class Oidc (message : String ) : QrCodeLoginException(message)
1481+
14801482 /* *
14811483 * The other device has signaled to us that the login has failed.
14821484 */
1483- LOGIN_FAILURE ,
1485+ class LoginFailure (message : String ) : QrCodeLoginException(message)
1486+
14841487 /* *
14851488 * An unexpected message was received from the other device.
14861489 */
1487- UNEXPECTED_MESSAGE ,
1490+ class UnexpectedMessage (message : String ) : QrCodeLoginException(message)
1491+
14881492 /* *
14891493 * An error happened while exchanging messages with the other device.
14901494 */
1491- SECURE_CHANNEL ,
1495+ class SecureChannel (message : String ) : QrCodeLoginException(message)
1496+
14921497 /* *
14931498 * The cross-process refresh lock failed to be initialized.
14941499 */
1495- CROSS_PROCESS_REFRESH_LOCK ,
1500+ class CrossProcessRefreshLock (message : String ) : QrCodeLoginException(message)
1501+
14961502 /* *
14971503 * An error happened while we were trying to discover our user and device
14981504 * ID, after we have acquired an access token from the OIDC provider.
14991505 */
1500- USER_ID_DISCOVERY ,
1506+ class UserIdDiscovery (message : String ) : QrCodeLoginException(message)
1507+
15011508 /* *
15021509 * We failed to set the session tokens after we figured out our device and
15031510 * user IDs.
15041511 */
1505- SESSION_TOKENS ,
1512+ class SessionTokens (message : String ) : QrCodeLoginException(message)
1513+
15061514 /* *
15071515 * The device keys failed to be uploaded after we successfully logged in.
15081516 */
1509- DEVICE_KEY_UPLOAD ,
1517+ class DeviceKeyUpload (message : String ) : QrCodeLoginException(message)
1518+
15101519 /* *
15111520 * The secrets bundle we received from the existing device failed to be
15121521 * imported.
15131522 */
1514- SECRET_IMPORT ;
1515- companion object
1516- }
1517-
1523+ class SecretImport (message : String ) : QrCodeLoginException(message)
1524+
15181525
1519- public object FfiConverterTypeQRCodeLoginError: FfiConverterRustBuffer<QrCodeLoginError> {
1520- override fun read (buf : ByteBuffer ) = try {
1521- QrCodeLoginError .values()[buf.getInt() - 1 ]
1522- } catch (e: IndexOutOfBoundsException ) {
1523- throw RuntimeException (" invalid enum value, something is very wrong!!" , e)
1526+ companion object ErrorHandler : UniffiRustCallStatusErrorHandler<QrCodeLoginException> {
1527+ override fun lift (error_buf : RustBuffer .ByValue ): QrCodeLoginException = FfiConverterTypeQRCodeLoginError .lift(error_buf)
15241528 }
1529+ }
15251530
1526- override fun allocationSize (value : QrCodeLoginError ) = 4UL
1531+ public object FfiConverterTypeQRCodeLoginError : FfiConverterRustBuffer<QrCodeLoginException> {
1532+ override fun read (buf : ByteBuffer ): QrCodeLoginException {
1533+
1534+ return when (buf.getInt()) {
1535+ 1 -> QrCodeLoginException .Oidc (FfiConverterString .read(buf))
1536+ 2 -> QrCodeLoginException .LoginFailure (FfiConverterString .read(buf))
1537+ 3 -> QrCodeLoginException .UnexpectedMessage (FfiConverterString .read(buf))
1538+ 4 -> QrCodeLoginException .SecureChannel (FfiConverterString .read(buf))
1539+ 5 -> QrCodeLoginException .CrossProcessRefreshLock (FfiConverterString .read(buf))
1540+ 6 -> QrCodeLoginException .UserIdDiscovery (FfiConverterString .read(buf))
1541+ 7 -> QrCodeLoginException .SessionTokens (FfiConverterString .read(buf))
1542+ 8 -> QrCodeLoginException .DeviceKeyUpload (FfiConverterString .read(buf))
1543+ 9 -> QrCodeLoginException .SecretImport (FfiConverterString .read(buf))
1544+ else -> throw RuntimeException (" invalid error enum value, something is very wrong!!" )
1545+ }
1546+
1547+ }
15271548
1528- override fun write (value : QrCodeLoginError , buf : ByteBuffer ) {
1529- buf.putInt(value.ordinal + 1 )
1549+ override fun allocationSize (value : QrCodeLoginException ): ULong {
1550+ return 4UL
15301551 }
1531- }
15321552
1553+ override fun write (value : QrCodeLoginException , buf : ByteBuffer ) {
1554+ when (value) {
1555+ is QrCodeLoginException .Oidc -> {
1556+ buf.putInt(1 )
1557+ Unit
1558+ }
1559+ is QrCodeLoginException .LoginFailure -> {
1560+ buf.putInt(2 )
1561+ Unit
1562+ }
1563+ is QrCodeLoginException .UnexpectedMessage -> {
1564+ buf.putInt(3 )
1565+ Unit
1566+ }
1567+ is QrCodeLoginException .SecureChannel -> {
1568+ buf.putInt(4 )
1569+ Unit
1570+ }
1571+ is QrCodeLoginException .CrossProcessRefreshLock -> {
1572+ buf.putInt(5 )
1573+ Unit
1574+ }
1575+ is QrCodeLoginException .UserIdDiscovery -> {
1576+ buf.putInt(6 )
1577+ Unit
1578+ }
1579+ is QrCodeLoginException .SessionTokens -> {
1580+ buf.putInt(7 )
1581+ Unit
1582+ }
1583+ is QrCodeLoginException .DeviceKeyUpload -> {
1584+ buf.putInt(8 )
1585+ Unit
1586+ }
1587+ is QrCodeLoginException .SecretImport -> {
1588+ buf.putInt(9 )
1589+ Unit
1590+ }
1591+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
1592+ }
15331593
1594+ }
15341595
15351596
15361597
0 commit comments