jlcodes99/cockpit-tools · warning

[account-sync] Failed to emit ${ACTIVE_PLATFORM_FOCUS_EVENT}

Error message

[account-sync] Failed to emit ${ACTIVE_PLATFORM_FOCUS_EVENT}:

What it means

emitActivePlatformFocus emits the ACTIVE_PLATFORM_FOCUS_EVENT cross-window via Tauri's emit; a rejection is caught and logged with this warning. The focused-platform notification is lost, so other windows won't update their active platform highlight. Like the other account-sync emitters it is intentionally non-fatal.

Source

Thrown at src/utils/accountSyncEvents.ts:154

}

export function persistFloatingCardPlatform(platformId: PlatformId): void {
  try {
    localStorage.setItem(FLOATING_CARD_PLATFORM_STORAGE_KEY, platformId);
  } catch {
    // ignore
  }
}

export async function emitActivePlatformFocus(payload: ActivePlatformFocusPayload) {
  persistFloatingCardPlatform(payload.platformId);
  try {
    await emit<ActivePlatformFocusPayload>(ACTIVE_PLATFORM_FOCUS_EVENT, {
      ...payload,
      sourceWindowLabel: payload.sourceWindowLabel ?? resolveSourceWindowLabel(),
    });
  } catch (error) {
    console.warn(`[account-sync] Failed to emit ${ACTIVE_PLATFORM_FOCUS_EVENT}:`, error);
  }
}

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Inspect the caught error; if it is a serialization failure, normalize the payload to plain JSON-safe values
  2. Guard the emit until Tauri event API is available (listen/emit readiness) and skip emits after unmount
  3. Verify the event name constant matches what listening windows registered
  4. Implement focus-state re-sync on window focus so a dropped event self-heals

Example fix

// before
await emit(ACTIVE_PLATFORM_FOCUS_EVENT, { ...payload, at: new Date() });
// after
await emit(ACTIVE_PLATFORM_FOCUS_EVENT, { ...payload, at: Date.now() });
Defensive patterns

Strategy: try-catch

Validate before calling

if (!isEmitPayloadSafe(payload)) {
  console.warn('skip focus emit: payload not serializable');
  return;
}

Type guard

function isActivePlatformFocusPayload(v: unknown): v is ActivePlatformFocusPayload {
  return isPlainObject(v) && typeof (v as { platform?: unknown }).platform === 'string';
}

Try / catch

try {
  await emit<ActivePlatformFocusPayload>(ACTIVE_PLATFORM_FOCUS_EVENT, payload);
} catch (error) {
  console.warn(`[account-sync] Failed to emit ${ACTIVE_PLATFORM_FOCUS_EVENT}:`, error);
}

Prevention

When it happens

Trigger: await emit<ActivePlatformFocusPayload>(ACTIVE_PLATFORM_FOCUS_EVENT, ...) rejects: webview/Tauri IPC not initialized yet, app teardown, invalid or non-serializable ActivePlatformFocusPayload fields, or emitting from a context without event permission.

Common situations: MainApp firing focus events on mount before the event system is ready; rapid window focus changes during shutdown; payload refactor introducing undefined/class values.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/df061cb1c0cec505. Report an issue: GitHub.