tonhowtf/omniget · error

[omnidisc] stream events subscribe failed

Error message

[omnidisc] stream events subscribe failed

What it means

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.

Solutions

  1. Ensure initStream is only called inside the Tauri webview runtime (guard with a capability check like `('__TAURI_INTERNALS__' in window)`).
  2. Await initStream before triggering any stream commands; check `initialized` after.
  3. Fix teardownStream so init is never re-entered while a previous subscribe is pending (idempotent init).
  4. Verify the backend actually emits on the `omnidisc://stream` topic with matching payload types.

Example fix

// before
await initStream();
// after
if (initialized) return;
await initStream();
if (!initialized) console.error('stream store unavailable');
Defensive patterns

Strategy: retry

Validate before calling

if (!('__TAURI_INTERNALS__' in window)) throw new Error('Tauri runtime unavailable');
if (initialized || initInFlight) return;

Type guard

export function isTauri(): boolean {
  return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
}

Try / catch

try {
  unlisten = await listen<StreamEventPayload>("omnidisc://stream", onStreamEvent);
  initialized = true;
} catch (e) {
  initialized = false;
  console.warn("[omnidisc] stream events subscribe failed", errorText(e));
  await retryWithBackoff(initStream, { attempts: 3 });
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/56ee480f325f49ec. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/stores/omnidisc-stream-store.svelte.ts:348

        publishing = null;
        previewImage = null;
      } else if (p.type === "stream_preview" && typeof p.image === "string") {
        previewImage = p.image;
      } else if (p.type === "stream" && typeof p.user_id === "string") {
        markStreamer(p.user_id, p.active === true);
        if (p.active !== true && watchingIds.includes(p.user_id)) {
          void unwatchStream(p.user_id);
        }
      } else if (p.type === "state" && (p.state === "idle" || p.state === "failed")) {
        streamers = {};
        previewImage = null;
        publishing = null;
        for (const id of watchingIds) void unwatchStream(id);
      }
    });
  } catch (e) {
    initialized = false;
    console.warn("[omnidisc] stream events subscribe failed", errorText(e));
  }
}

export function teardownStream() {
  if (unlisten) unlisten();
  unlisten = null;
  initialized = false;
}

View on GitHub (pinned to 8600b91f42)