From 8dcdcb9a7df3838e2b3ba4ef2d50e22126709ec6 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 20 Feb 2024 19:57:11 +0100 Subject: wallet-core: better error handling for DB issues in init request --- packages/taler-wallet-core/src/wallet.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'packages/taler-wallet-core/src/wallet.ts') diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 5a6cfb96b..dfe7b2395 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -49,6 +49,7 @@ import { StoredBackupList, TalerError, TalerErrorCode, + TalerProtocolTimestamp, TalerUriAction, TestingWaitTransactionRequest, TimerAPI, @@ -168,6 +169,7 @@ import { importDb, openStoredBackupsDatabase, openTalerDatabase, + timestampProtocolToDb, } from "./db.js"; import { computeDepositTransactionStatus, @@ -646,6 +648,21 @@ async function dispatchRequestInternal( } case WalletApiOperation.InitWallet: { logger.trace("initializing wallet"); + // Write to the DB to make sure that we're failing early in + // case the DB is not writeable. + try { + await ws.db.runReadWriteTx(["config"], async (tx) => { + tx.config.put({ + key: ConfigRecordKey.LastInitInfo, + value: timestampProtocolToDb(TalerProtocolTimestamp.now()), + }); + }); + } catch (e) { + logger.error("error writing to database during initialization"); + throw TalerError.fromDetail(TalerErrorCode.WALLET_DB_UNAVAILABLE, { + innerError: getErrorDetailFromException(e), + }); + } ws.initCalled = true; if (ws.config.testing.skipDefaults) { logger.trace("skipping defaults"); @@ -1324,8 +1341,8 @@ async function handleCoreApiRequest( id: string, payload: unknown, ): Promise { - await ws.ensureWalletDbOpen(); try { + await ws.ensureWalletDbOpen(); const result = await dispatchRequestInternal(ws, operation as any, payload); return { type: "response", -- cgit v1.2.3