From fb37150dfd7442fee8da62b42ca9eec0730c48da Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 5 Dec 2017 13:45:37 +0000 Subject: [PATCH] Doc exception handling fun --- src/crypto/store/indexeddb-crypto-store-backend.js | 7 +++++++ src/crypto/store/indexeddb-crypto-store.js | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/crypto/store/indexeddb-crypto-store-backend.js b/src/crypto/store/indexeddb-crypto-store-backend.js index 6b91fa43f..bd812a979 100644 --- a/src/crypto/store/indexeddb-crypto-store-backend.js +++ b/src/crypto/store/indexeddb-crypto-store-backend.js @@ -359,7 +359,14 @@ function createDatabase(db) { outgoingRoomKeyRequestsStore.createIndex("state", "state"); } +/* + * Aborts a transaction with a given exception + * The transaction promise will be rejected with this exception. + */ function abortWithException(txn, e) { + // We cheekily stick our exception onto the transaction object here + // We could alternatively make the thing we pass back to the app + // an object containing the transaction and exception. txn._mx_abortexception = e; txn.abort(); } diff --git a/src/crypto/store/indexeddb-crypto-store.js b/src/crypto/store/indexeddb-crypto-store.js index 2629bf588..d5ad0ceaa 100644 --- a/src/crypto/store/indexeddb-crypto-store.js +++ b/src/crypto/store/indexeddb-crypto-store.js @@ -302,7 +302,11 @@ export default class IndexedDBCryptoStore { * transaction object: an opaque object that should be passed * to store functions. * @return {Promise} Promise that resolves with the result of the `func` - * when the transaction is complete + * when the transaction is complete. If the backend is + * async (ie. the indexeddb backend) any of the callback + * functions throwing an exception will cause this promise to + * reject with that exception. On synchronous backends, the + * exception will propagate to the caller of the getFoo method. */ doTxn(mode, stores, func) { return this._connect().then((backend) => {