@@ -189,7 +189,7 @@ export class SimpleDb {
189
189
/**
190
190
* Opens the specified database, creating or upgrading it if necessary.
191
191
*/
192
- async ensureDb ( ) : Promise < IDBDatabase > {
192
+ async ensureDb ( action : string ) : Promise < IDBDatabase > {
193
193
if ( ! this . db ) {
194
194
logDebug ( LOG_TAG , 'Opening database:' , this . name ) ;
195
195
this . db = await new Promise < IDBDatabase > ( ( resolve , reject ) => {
@@ -208,6 +208,7 @@ export class SimpleDb {
208
208
request . onblocked = ( ) => {
209
209
reject (
210
210
new IndexedDbTransactionError (
211
+ action ,
211
212
'Cannot upgrade IndexedDB schema while another tab is open. ' +
212
213
'Close all tabs that access Firestore and reload this page to proceed.'
213
214
)
@@ -228,7 +229,7 @@ export class SimpleDb {
228
229
)
229
230
) ;
230
231
} else {
231
- reject ( new IndexedDbTransactionError ( error ) ) ;
232
+ reject ( new IndexedDbTransactionError ( action , error ) ) ;
232
233
}
233
234
} ;
234
235
@@ -274,6 +275,7 @@ export class SimpleDb {
274
275
}
275
276
276
277
async runTransaction < T > (
278
+ action : string ,
277
279
mode : SimpleDbTransactionMode ,
278
280
objectStores : string [ ] ,
279
281
transactionFn : ( transaction : SimpleDbTransaction ) => PersistencePromise < T >
@@ -285,10 +287,11 @@ export class SimpleDb {
285
287
++ attemptNumber ;
286
288
287
289
try {
288
- this . db = await this . ensureDb ( ) ;
290
+ this . db = await this . ensureDb ( action ) ;
289
291
290
292
const transaction = SimpleDbTransaction . open (
291
293
this . db ,
294
+ action ,
292
295
readonly ? 'readonly' : 'readwrite' ,
293
296
objectStores
294
297
) ;
@@ -424,8 +427,11 @@ export interface IterateOptions {
424
427
export class IndexedDbTransactionError extends FirestoreError {
425
428
name = 'IndexedDbTransactionError' ;
426
429
427
- constructor ( cause : Error | string ) {
428
- super ( Code . UNAVAILABLE , 'IndexedDB transaction failed: ' + cause ) ;
430
+ constructor ( actionName : string , cause : Error | string ) {
431
+ super (
432
+ Code . UNAVAILABLE ,
433
+ `IndexedDB transaction '${ actionName } ' failed: ${ cause } `
434
+ ) ;
429
435
}
430
436
}
431
437
@@ -450,24 +456,31 @@ export class SimpleDbTransaction {
450
456
451
457
static open (
452
458
db : IDBDatabase ,
459
+ action : string ,
453
460
mode : IDBTransactionMode ,
454
461
objectStoreNames : string [ ]
455
462
) : SimpleDbTransaction {
456
463
try {
457
- return new SimpleDbTransaction ( db . transaction ( objectStoreNames , mode ) ) ;
464
+ return new SimpleDbTransaction (
465
+ action ,
466
+ db . transaction ( objectStoreNames , mode )
467
+ ) ;
458
468
} catch ( e ) {
459
- throw new IndexedDbTransactionError ( e ) ;
469
+ throw new IndexedDbTransactionError ( action , e ) ;
460
470
}
461
471
}
462
472
463
- constructor ( private readonly transaction : IDBTransaction ) {
473
+ constructor (
474
+ private readonly action : string ,
475
+ private readonly transaction : IDBTransaction
476
+ ) {
464
477
this . transaction . oncomplete = ( ) => {
465
478
this . completionDeferred . resolve ( ) ;
466
479
} ;
467
480
this . transaction . onabort = ( ) => {
468
481
if ( transaction . error ) {
469
482
this . completionDeferred . reject (
470
- new IndexedDbTransactionError ( transaction . error )
483
+ new IndexedDbTransactionError ( action , transaction . error )
471
484
) ;
472
485
} else {
473
486
this . completionDeferred . resolve ( ) ;
@@ -477,7 +490,9 @@ export class SimpleDbTransaction {
477
490
const error = checkForAndReportiOSError (
478
491
( event . target as IDBRequest ) . error !
479
492
) ;
480
- this . completionDeferred . reject ( new IndexedDbTransactionError ( error ) ) ;
493
+ this . completionDeferred . reject (
494
+ new IndexedDbTransactionError ( action , error )
495
+ ) ;
481
496
} ;
482
497
}
483
498
0 commit comments