{"record":{"id":"213edcbb5e38628c","repo":"tonhowtf/omniget","slug":"omnidisc-could-not-subscribe-to-gateway-events","errorCode":null,"errorMessage":"[omnidisc] could not subscribe to gateway events","messagePattern":"\\[omnidisc\\] could not subscribe to gateway events","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/stores/omnidisc-store.svelte.ts","lineNumber":1441,"sourceCode":"    const offDispatch = await listen<GatewayDispatchEvent>(\"omnidisc://dispatch\", (event) => {\n      const payload = event.payload;\n      const instance = instanceByUrl(payload.url);\n      if (!instance) return;\n      try {\n        handleDispatch(instance, payload.t, payload.d);\n      } catch (e) {\n        console.warn(\"[omnidisc] dispatch handler failed\", payload.t, errorText(e));\n      }\n    });\n    const offStatus = await listen<GatewayStatusEvent>(\"omnidisc://status\", (event) => handleStatus(event.payload));\n    const offUpload = await listen<unknown>(\"omnidisc://upload\", (event) => handleUploadProgress(event.payload));\n    const offDecrypted = await listen<unknown>(\"omnidisc://decrypted\", (event) =>\n      handleDecryptedEvent(event.payload),\n    );\n    unlisteners = [offDispatch, offStatus, offUpload, offDecrypted];\n  } catch (e) {\n    initialized = false;\n    console.warn(\"[omnidisc] could not subscribe to gateway events\", errorText(e));\n    return;\n  }\n  for (const instance of instances) {\n    if (isDemo(instance.id)) continue;\n    void connectGateway(instance);\n  }\n}\n\nexport function teardownOmnidisc() {\n  for (const off of unlisteners) off();\n  unlisteners = [];\n  initialized = false;\n}\n\nexport async function connectGateway(instance: OmnidiscInstance): Promise<void> {\n  if (isDemo(instance.id)) return;\n  instance.status = \"connecting\";\n  instance.error = undefined;","sourceCodeStart":1423,"sourceCodeEnd":1459,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src/lib/stores/omnidisc-store.svelte.ts#L1423-L1459","documentation":"During store init, the store subscribes to backend events (`omnidisc://dispatch`, `omnidisc://status`, `omnidisc://upload`, `omnidisc://decrypted`) via Tauri's listen(). If any listen() call rejects (event not registered, app handle unavailable) the store resets `initialized = false`, logs this warning, and aborts init — the gateway will never be connected for any instance, so all realtime features stay dead until init is retried.","triggerScenarios":"Calling the store's init/connect flow when one of the four listen<T>(\"omnidisc://…\") promises rejects — typically the Tauri runtime not ready, plugin not initialized, or running outside a Tauri window (e.g. plain browser during dev).","commonSituations":"Developing in a browser without the Tauri runtime so invoke/listen are stubbed or absent; app updated with renamed events while a stale backend runs; very early subscription before the app setup completes.","solutions":["Check errorText(e) to see which listen() call failed","Ensure the app is running inside the Tauri webview (not a plain browser tab) and the event-emitting Rust side is initialized before the frontend subscribes","Retry init after the runtime is ready — initialized was reset to false so a re-init is possible","Verify frontend event names match the backend emit strings exactly"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// only init inside the Tauri runtime\nif (!(\"__TAURI_INTERNALS__\" in window)) { console.warn(\"not in Tauri runtime\"); return; }\n","typeGuard":null,"tryCatchPattern":"try {\n  offDispatch = await listen(\"omnidisc://dispatch\", ...);\n  offStatus = await listen(\"omnidisc://status\", ...);\n} catch (e) {\n  initialized = false;\n  console.warn(\"[omnidisc] could not subscribe to gateway events\", errorText(e));\n  return;\n}","preventionTips":["Subscribe to events only after the Tauri runtime is ready","Unregister old listeners before re-initializing to avoid duplicates","Gate init on a readiness flag so a failed init can be retried once"],"tags":["tauri","svelte","event-listener","initialization"],"backgroundTag":"event-subscription-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}