« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static
diff options
context:
space:
mode:
Diffstat (limited to 'src/static')
-rw-r--r--src/static/js/client.js17
-rw-r--r--src/static/js/search-worker.js5
2 files changed, 22 insertions, 0 deletions
diff --git a/src/static/js/client.js b/src/static/js/client.js
index 58f1acb9..9bef44a2 100644
--- a/src/static/js/client.js
+++ b/src/static/js/client.js
@@ -3455,6 +3455,7 @@ const wikiSearchInfo = initInfo('wikiSearchInfo', {
     whenWorkerAlive: [],
     whenWorkerReady: [],
     whenWorkerFailsToInitialize: [],
+    whenWorkerHasRuntimeError: [],
 
     whenDownloadBegins: [],
     whenDownloadsBegin: [],
@@ -3533,6 +3534,11 @@ function handleSearchWorkerStatusMessage(message) {
       dispatchInternalEvent(event, 'whenWorkerFailsToInitialize');
       break;
 
+    case 'runtime-error':
+      console.debug(`Search worker had an uncaught runtime error.`);
+      dispatchInternalEvent(event, 'whenWorkerHasRuntimeError');
+      break;
+
     default:
       console.warn(`Unknown status "${message.data.status}" <- from search worker`);
       break;
@@ -3782,6 +3788,10 @@ function addSidebarSearchInternalListeners() {
     trackSidebarSearchWorkerFailsToInitialize,
     updateSidebarSearchStatus);
 
+  wikiSearchInfo.event.whenWorkerHasRuntimeError.push(
+    trackSidebarSearchWorkerHasRuntimeError,
+    updateSidebarSearchStatus);
+
   wikiSearchInfo.event.whenDownloadsBegin.push(
     trackSidebarSearchDownloadsBegin,
     updateSidebarSearchStatus);
@@ -3973,6 +3983,13 @@ function trackSidebarSearchWorkerFailsToInitialize() {
   state.searchStage = 'failed';
 }
 
+function trackSidebarSearchWorkerHasRuntimeError() {
+  const {state} = sidebarSearchInfo;
+
+  state.workerStatus = 'failed';
+  state.searchStage = 'failed';
+}
+
 function trackSidebarSearchDownloadsBegin(event) {
   const {state} = sidebarSearchInfo;
 
diff --git a/src/static/js/search-worker.js b/src/static/js/search-worker.js
index 9a7827da..66c0cf2e 100644
--- a/src/static/js/search-worker.js
+++ b/src/static/js/search-worker.js
@@ -26,6 +26,7 @@ let status = null;
 let indexes = null;
 
 onmessage = handleWindowMessage;
+onerror = handleRuntimeError;
 postStatus('alive');
 
 Promise.all([
@@ -302,6 +303,10 @@ function importIndex(indexKey, indexData) {
   }
 }
 
+function handleRuntimeError() {
+  postStatus('runtime-error');
+}
+
 function handleWindowMessage(message) {
   switch (message.data.kind) {
     case 'action':