diff --git a/web/src/engine/predictive-text/worker-thread/src/main/index.ts b/web/src/engine/predictive-text/worker-thread/src/main/index.ts index 262492674f..318256ba54 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/index.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/index.ts @@ -267,7 +267,11 @@ export class LMLayerWorker { try { this._importScripts(url); } catch (err) { + // Does not catch errors thrown within the imported script. + // Does catch errors with the model script's file-path. this.error("Error occurred when attempting to load dictionary", err); + + // Remain in the model-unloaded state; the load attempt was unsuccessful. } } @@ -312,7 +316,14 @@ export class LMLayerWorker { this.state = { name: 'modelless', handleMessage: (payload) => { - // ...that message must have been 'load'! + // It is possible to remain in this state after a model loading error. + // In such cases, the hosting engine may signal a model-unload. + if (payload.message === 'unload') { + // We are already in a "model unloaded" state; no work needed! + return; + } + + // ...otherwise, that message must have been 'load'! if (payload.message !== 'load') { throw new Error(`invalid message; expected 'load' but got ${payload.message}`); }