{"record":{"id":"56ee480f325f49ec","repo":"tonhowtf/omniget","slug":"omnidisc-stream-events-subscribe-failed","errorCode":null,"errorMessage":"[omnidisc] stream events subscribe failed","messagePattern":"\\[omnidisc\\] stream events subscribe failed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/stores/omnidisc-stream-store.svelte.ts","lineNumber":348,"sourceCode":"        publishing = null;\n        previewImage = null;\n      } else if (p.type === \"stream_preview\" && typeof p.image === \"string\") {\n        previewImage = p.image;\n      } else if (p.type === \"stream\" && typeof p.user_id === \"string\") {\n        markStreamer(p.user_id, p.active === true);\n        if (p.active !== true && watchingIds.includes(p.user_id)) {\n          void unwatchStream(p.user_id);\n        }\n      } else if (p.type === \"state\" && (p.state === \"idle\" || p.state === \"failed\")) {\n        streamers = {};\n        previewImage = null;\n        publishing = null;\n        for (const id of watchingIds) void unwatchStream(id);\n      }\n    });\n  } catch (e) {\n    initialized = false;\n    console.warn(\"[omnidisc] stream events subscribe failed\", errorText(e));\n  }\n}\n\nexport function teardownStream() {\n  if (unlisten) unlisten();\n  unlisten = null;\n  initialized = false;\n}\n","sourceCodeStart":330,"sourceCodeEnd":357,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src/lib/stores/omnidisc-stream-store.svelte.ts#L330-L357","documentation":"initStream subscribes to the backend's stream event channel via Tauri's listen(). If the subscription itself fails (event system unavailable, app window/context invalid, backend not ready), the catch resets `initialized = false` and logs this warning. Without the subscription, stream state changes pushed from Rust will never reach the store.","triggerScenarios":"Calling initStream() before the Tauri IPC layer is ready, calling it twice concurrently (second subscribe fails or races), or a backend build missing the `omnidisc://stream` event emitter.","commonSituations":"Calling initStream during app startup in a context where invoke/listen is not yet available (e.g. SSR or test environment without a Tauri runtime); hot-reload leaving a stale unlisten; backend not emitting the event topic.","solutions":["Ensure initStream is only called inside the Tauri webview runtime (guard with a capability check like `('__TAURI_INTERNALS__' in window)`).","Await initStream before triggering any stream commands; check `initialized` after.","Fix teardownStream so init is never re-entered while a previous subscribe is pending (idempotent init).","Verify the backend actually emits on the `omnidisc://stream` topic with matching payload types."],"exampleFix":"// before\nawait initStream();\n// after\nif (initialized) return;\nawait initStream();\nif (!initialized) console.error('stream store unavailable');","handlingStrategy":"retry","validationCode":"if (!('__TAURI_INTERNALS__' in window)) throw new Error('Tauri runtime unavailable');\nif (initialized || initInFlight) return;","typeGuard":"export function isTauri(): boolean {\n  return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;\n}","tryCatchPattern":"try {\n  unlisten = await listen<StreamEventPayload>(\"omnidisc://stream\", onStreamEvent);\n  initialized = true;\n} catch (e) {\n  initialized = false;\n  console.warn(\"[omnidisc] stream events subscribe failed\", errorText(e));\n  await retryWithBackoff(initStream, { attempts: 3 });\n}","preventionTips":["Call initStream only after the Tauri webview signals readiness.","Make init idempotent and single-flight to prevent subscribe races.","Verify backend event topic names match exactly (omnidisc://stream).","Expose an initialized flag consumers must check before issuing stream commands."],"tags":["tauri","ipc","events","subscription"],"backgroundTag":"event-subscribe-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"}