famedly / matrix-dart-sdk

Matrix SDK written in pure Dart.
GNU Affero General Public License v3.0
52 stars 30 forks source link

Client initialization failed #1812

Closed NiallBunting closed 2 months ago

NiallBunting commented 3 months ago

Checklist

In which Project did the bug appear?

Other

If you selected \"Other\" as Project, please enter in which project the bug occurred.

No response

On which platform did the bug appear?

Android

SDK Version

0.29.2

Describe the problem caused by this bug

I'm trying to migrate over from HiveCollectionsDatabase to the new MatrixSdkDatabase. I don't know if there is documentation for how to migrate correctly but on the flutter doc page the example seems to not include the latest changes.

Anyway I'm running into ClientInitPreconditionError exceptions: !!!CRITICAL!!! Client initialization failed - LateInitializationError: Field '_clientBox@1543351407' has not been initialized..

I/flutter (11549): [Matrix] !!!CRITICAL!!! Client initialization failed - LateInitializationError: Field '_clientBox@1543351407' has not been initialized.
I/flutter (11549): #0      MatrixSdkDatabase._clientBox (package:matrix/src/database/matrix_sdk_database.dart)
I/flutter (11549): #1      MatrixSdkDatabase.getClient.<anonymous closure> (package:matrix/src/database/matrix_sdk_database.dart:381:28)
I/flutter (11549): #2      runBenchmarked (package:matrix/src/utils/run_benchmarked.dart:33:28)
I/flutter (11549): #3      MatrixSdkDatabase.getClient (package:matrix/src/database/matrix_sdk_database.dart:379:7)
I/flutter (11549): #4      Client.init (package:matrix/src/client.dart:1586:44)
I/flutter (11549): <asynchronous suspension>
I/flutter (11549): #5      MatrixProviderModel.login (package:myproj/models/matrixprovider.dart:200:7)
I/flutter (11549): <asynchronous suspension>
I/flutter (11549): #6      main.<anonymous closure> (package:myproj/main.dart:210:7)
I/flutter (11549): <asynchronous suspension>
I/flutter (11549): 

Steps To Reproduce

My init looks like this:

    _matrixClient = Client('MyClient',
        databaseBuilder: (_) async {
          final dir =
              await getApplicationSupportDirectory(); // Recommend path_provider package

          Database db = await openDatabase(
            dir.toString() + '/database.sql',
            password: "somepassword",
          );

          return MatrixSdkDatabase('matrixdatabase', database: db);
      },
      legacyDatabaseBuilder: (_) async {
         final dir =
              await getApplicationSupportDirectory(); // Recommend path_provider package
         final db = HiveCollectionsDatabase('hivedb', dir.path);
         await db.open();
         return db;
      },
      logLevel: kReleaseMode ? Level.warning : Level.verbose,
    );

Screenshots or Logs

No response

Security related

No response

krille-chan commented 3 months ago

Hey you are missing await database.open() in your databaseBuilder, similar like you did with HiveCollectionsDatabase