From f56fb8faa237f87de9fa7c6e8ec4cccaa132d145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= <33655937+jkoenig134@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:12:04 +0200 Subject: [PATCH] Fix/Failing initial sync breaks AccountController (#263) * fix: failing initial sync breaks AccountController * fix: make safer --- .../src/multiAccount/MultiAccountController.ts | 11 ++++++++++- packages/transport/src/core/TransportCoreErrors.ts | 4 ++++ .../src/modules/accounts/AccountController.ts | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/app-runtime/src/multiAccount/MultiAccountController.ts b/packages/app-runtime/src/multiAccount/MultiAccountController.ts index c8a0eef5f..55728c7ec 100644 --- a/packages/app-runtime/src/multiAccount/MultiAccountController.ts +++ b/packages/app-runtime/src/multiAccount/MultiAccountController.ts @@ -99,7 +99,16 @@ export class MultiAccountController { this._log.trace(`Initializing AccountController for local account ${id}...`); const accountController = new AccountController(this.transport, db, this.transport.config); - await accountController.init(); + + await accountController.init().catch((error) => { + if (error instanceof CoreError && TransportCoreErrors.general.accountControllerInitialSyncFailed().equals(error)) { + this._log.error(`Initial sync of AccountController for local account ${id} failed.`, error); + return; + } + + throw error; + }); + this._log.trace(`AccountController for local account ${id} initialized.`); this._openAccounts[localAccount.id.toString()] = accountController; diff --git a/packages/transport/src/core/TransportCoreErrors.ts b/packages/transport/src/core/TransportCoreErrors.ts index 15a6db820..4c96e5139 100644 --- a/packages/transport/src/core/TransportCoreErrors.ts +++ b/packages/transport/src/core/TransportCoreErrors.ts @@ -197,6 +197,10 @@ class General { public invalidTruncatedReference() { return new CoreError("error.transport.files.invalidTruncatedReference", "invalid truncated reference"); } + + public accountControllerInitialSyncFailed() { + return new CoreError("error.transport.accountControllerInitialSyncFailed", "The initial sync of the AccountController failed."); + } } export class TransportCoreErrors { diff --git a/packages/transport/src/modules/accounts/AccountController.ts b/packages/transport/src/modules/accounts/AccountController.ts index d535b1324..3286d03e9 100644 --- a/packages/transport/src/modules/accounts/AccountController.ts +++ b/packages/transport/src/modules/accounts/AccountController.ts @@ -182,7 +182,10 @@ export class AccountController { await this.syncDatawallet(); await this.devices.update(device!); } - await this.syncDatawallet(); + + await this.syncDatawallet().catch(() => { + throw TransportCoreErrors.general.accountControllerInitialSyncFailed(); + }); return this; }