Skip to content

Commit

Permalink
Handle async index db initialization errors, fixes tutadb 1805
Browse files Browse the repository at this point in the history
Errors while initializing the DBFacade are now handled inside DBFacade and re thrown as DBError to prevent uncaught errors.

Errors from the event queue are also not reported as uncaught error by EntityClient anymore as they are thrown anyway.
  • Loading branch information
bedhub committed Jun 5, 2024
1 parent 62402ec commit b39833d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/api/worker/EventBusClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { SleepDetector } from "./utils/SleepDetector.js"
import sysModelInfo from "../entities/sys/ModelInfo.js"
import tutanotaModelInfo from "../entities/tutanota/ModelInfo.js"
import { resolveTypeReference } from "../common/EntityFunctions.js"
import { ReportedMailFieldMarker, PhishingMarkerWebsocketData, PhishingMarkerWebsocketDataTypeRef } from "../entities/tutanota/TypeRefs"
import { PhishingMarkerWebsocketData, PhishingMarkerWebsocketDataTypeRef, ReportedMailFieldMarker } from "../entities/tutanota/TypeRefs"
import { UserFacade } from "./facades/UserFacade"
import { ExposedProgressTracker } from "../main/ProgressTracker.js"

Expand Down Expand Up @@ -558,7 +558,6 @@ export class EventBusClient {
await this.processEventBatch(modification)
} catch (e) {
console.log("ws error while processing event batches", e)
this.listener.onError(e)
throw e
}

Expand Down
1 change: 1 addition & 0 deletions src/api/worker/WorkerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class WorkerImpl implements NativeInterface {
// Otherwise uncaught error handler might end up in an infinite loop for test cases.
if (workerScope && !isMainOrNode()) {
workerScope.addEventListener("unhandledrejection", (event: PromiseRejectionEvent) => {
console.error("workerImpl.unhandledrejection", event, event.reason)
this.sendError(event.reason)
})

Expand Down
6 changes: 3 additions & 3 deletions src/api/worker/search/DbFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class DbFacade {
private _activeTransactions: number
indexingSupported: boolean = true

constructor(version: number, onupgrade: (event: any, db: IDBDatabase, dbFacade: DbFacade) => void) {
constructor(version: number, onupgrade: (event: any, db: IDBDatabase, dbFacade: DbFacade) => Promise<void> | void) {
this._activeTransactions = 0
this._db = new LazyLoaded(() => {
if (!this.indexingSupported) {
Expand Down Expand Up @@ -86,11 +86,11 @@ export class DbFacade {
}
}

DBOpenRequest.onupgradeneeded = (event: IDBVersionChangeEvent) => {
DBOpenRequest.onupgradeneeded = async (event: IDBVersionChangeEvent) => {
//console.log("upgrade db", event)
try {
// @ts-ignore
onupgrade(event, event.target.result, this)
await onupgrade(event, event.target.result, this)
} catch (e) {
reject(new DbError("could not create object store for DB " + this._id, e))
}
Expand Down

0 comments on commit b39833d

Please sign in to comment.