diff options
author | Florian Dold <florian@dold.me> | 2024-02-20 19:57:11 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-02-20 19:57:11 +0100 |
commit | 8dcdcb9a7df3838e2b3ba4ef2d50e22126709ec6 (patch) | |
tree | d6caa6f61acb27472fad707f790fb3eeca478a72 /packages/taler-wallet-core/src | |
parent | d70f722866b62e4a0076c805b65d66d5a049b366 (diff) | |
download | wallet-core-8dcdcb9a7df3838e2b3ba4ef2d50e22126709ec6.tar.xz |
wallet-core: better error handling for DB issues in init request
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 4 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 672c1d9aa..ab7a1562a 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1327,6 +1327,7 @@ export enum ConfigRecordKey { DevMode = "devMode", // Only for testing, do not use! TestLoopTx = "testTxLoop", + LastInitInfo = "lastInitInfo", } /** @@ -1340,7 +1341,8 @@ export type ConfigRecord = } | { key: ConfigRecordKey.CurrencyDefaultsApplied; value: boolean } | { key: ConfigRecordKey.DevMode; value: boolean } - | { key: ConfigRecordKey.TestLoopTx; value: number }; + | { key: ConfigRecordKey.TestLoopTx; value: number } + | { key: ConfigRecordKey.LastInitInfo; value: DbProtocolTimestamp }; export interface WalletBackupConfState { deviceId: string; 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<Op extends WalletApiOperation>( } 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<CoreApiResponse> { - await ws.ensureWalletDbOpen(); try { + await ws.ensureWalletDbOpen(); const result = await dispatchRequestInternal(ws, operation as any, payload); return { type: "response", |