From: Chris Duncan Date: Thu, 6 Aug 2026 05:47:57 +0000 (-0700) Subject: Refactor vault host code error handling. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=28df765d7b0d7b68977c7383c9393c7845304ecc;p=libnemo.git Refactor vault host code error handling. --- diff --git a/src/lib/vault/index.ts b/src/lib/vault/index.ts index 5d19bd4..943a743 100644 --- a/src/lib/vault/index.ts +++ b/src/lib/vault/index.ts @@ -46,6 +46,7 @@ export class Vault { this.#worker = new Worker(this.#url, { type: 'module' }) this.#worker.addEventListener('message', this.#report) this.#worker.addEventListener('error', this.terminate) + this.#worker.addEventListener('messageerror', this.terminate) } NODE: { this.#worker = new NodeWorker(vaultWorker, { @@ -55,6 +56,8 @@ export class Vault { }) this.#url = dec.toString(this.#worker.threadId) this.#worker.on('message', listener) + this.#worker.on('error', this.terminate) + this.#worker.on('messageerror', this.terminate) } } @@ -121,7 +124,7 @@ export class Vault { const { taskUrl, taskId, error, isLocked } = results if (taskUrl === this.#url) { if (typeof taskId !== 'string') { - throw new Error('Vault worker job invalid ID', { cause: typeof taskId }) + return this.terminate() } if (typeof isLocked === 'boolean' && this.#isLocked !== isLocked) { this.#isLocked = isLocked @@ -129,11 +132,13 @@ export class Vault { } if (taskId === 'autolock') return const task = this.#tasks.get(taskId) - this.#tasks.delete(taskId) if (task == null) { - throw new Error(`Vault worker returned results without an associated task for ID ${taskId}`) + console.warn(`Vault worker returned results without an associated task for ID ${taskId}`) + return } - const { resolve, reject } = task + const { resolve, reject, timeout } = task + this.#tasks.delete(taskId) + clearTimeout(timeout) if (error != null) { reject(new Error(String(error))) } else {