diff options
author | Sebastian <sebasjm@gmail.com> | 2024-02-12 15:54:49 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-02-12 16:05:51 -0300 |
commit | 86194c61457f2e2e534cd05071bde9633e205ad3 (patch) | |
tree | 2eb7794af5b6575680a259fb066bc698d7a71ed0 /packages/taler-wallet-core/src/util | |
parent | 975a087956c8c392801515db4b6809a368b83e20 (diff) | |
download | wallet-core-86194c61457f2e2e534cd05071bde9633e205ad3.tar.xz |
add more info when wallet-core is not available
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r-- | packages/taler-wallet-core/src/util/promiseUtils.ts | 17 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/util/query.ts | 17 |
2 files changed, 24 insertions, 10 deletions
diff --git a/packages/taler-wallet-core/src/util/promiseUtils.ts b/packages/taler-wallet-core/src/util/promiseUtils.ts index df4cc343b..d152a12f4 100644 --- a/packages/taler-wallet-core/src/util/promiseUtils.ts +++ b/packages/taler-wallet-core/src/util/promiseUtils.ts @@ -23,6 +23,7 @@ export interface OpenedPromise<T> { promise: Promise<T>; resolve: (val: T) => void; reject: (err: any) => void; + lastError?: any; } /** @@ -33,16 +34,22 @@ export interface OpenedPromise<T> { */ export function openPromise<T>(): OpenedPromise<T> { let resolve: ((x?: any) => void) | null = null; - let reject: ((reason?: any) => void) | null = null; + let promiseReject: ((reason?: any) => void) | null = null; const promise = new Promise<T>((res, rej) => { resolve = res; - reject = rej; + promiseReject = rej; }); - if (!(resolve && reject)) { + if (!(resolve && promiseReject)) { // Never happens, unless JS implementation is broken - throw Error(); + throw Error("JS implementation is broken"); } - return { resolve, reject, promise }; + const result: OpenedPromise<T> = { resolve, reject: promiseReject, promise }; + function saveLastError(reason?: any) { + result.lastError = reason; + promiseReject!(reason); + } + result.reject = saveLastError; + return result; } export class AsyncCondition { diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index efb1a3f42..8274e252b 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -34,6 +34,7 @@ import { IDBCursor, IDBKeyPath, IDBKeyRange, + IDBOpenDBRequest, } from "@gnu-taler/idb-bridge"; import { Codec, Logger, j2s } from "@gnu-taler/taler-util"; @@ -250,9 +251,9 @@ export function openDatabase( ): Promise<IDBDatabase> { return new Promise<IDBDatabase>((resolve, reject) => { const req = idbFactory.open(databaseName, databaseVersion); - req.onerror = (e) => { - logger.error("database error", e); - reject(new Error("database error")); + req.onerror = (event) => { + // @ts-expect-error + reject(new Error(`database opening error`, { cause: req.error })); }; req.onsuccess = (e) => { req.result.onversionchange = (evt: IDBVersionChangeEvent) => { @@ -268,11 +269,17 @@ export function openDatabase( const db = req.result; const newVersion = e.newVersion; if (!newVersion) { - throw Error("upgrade needed, but new version unknown"); + // @ts-expect-error + throw Error("upgrade needed, but new version unknown", { + cause: req.error, + }); } const transaction = req.transaction; if (!transaction) { - throw Error("no transaction handle available in upgrade handler"); + // @ts-expect-error + throw Error("no transaction handle available in upgrade handler", { + cause: req.error, + }); } logger.info( `handling upgradeneeded event on ${databaseName} from ${e.oldVersion} to ${e.newVersion}`, |