{"record":{"id":"df061cb1c0cec505","repo":"jlcodes99/cockpit-tools","slug":"account-sync-failed-to-emit-active-platform-fo","errorCode":null,"errorMessage":"[account-sync] Failed to emit ${ACTIVE_PLATFORM_FOCUS_EVENT}:","messagePattern":"\\[account-sync\\] Failed to emit (.+?):","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/utils/accountSyncEvents.ts","lineNumber":154,"sourceCode":"}\n\nexport function persistFloatingCardPlatform(platformId: PlatformId): void {\n  try {\n    localStorage.setItem(FLOATING_CARD_PLATFORM_STORAGE_KEY, platformId);\n  } catch {\n    // ignore\n  }\n}\n\nexport async function emitActivePlatformFocus(payload: ActivePlatformFocusPayload) {\n  persistFloatingCardPlatform(payload.platformId);\n  try {\n    await emit<ActivePlatformFocusPayload>(ACTIVE_PLATFORM_FOCUS_EVENT, {\n      ...payload,\n      sourceWindowLabel: payload.sourceWindowLabel ?? resolveSourceWindowLabel(),\n    });\n  } catch (error) {\n    console.warn(`[account-sync] Failed to emit ${ACTIVE_PLATFORM_FOCUS_EVENT}:`, error);\n  }\n}\n","sourceCodeStart":136,"sourceCodeEnd":157,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/utils/accountSyncEvents.ts#L136-L157","documentation":"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.","triggerScenarios":"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.","commonSituations":"MainApp firing focus events on mount before the event system is ready; rapid window focus changes during shutdown; payload refactor introducing undefined/class values.","solutions":["Inspect the caught error; if it is a serialization failure, normalize the payload to plain JSON-safe values","Guard the emit until Tauri event API is available (listen/emit readiness) and skip emits after unmount","Verify the event name constant matches what listening windows registered","Implement focus-state re-sync on window focus so a dropped event self-heals"],"exampleFix":"// before\nawait emit(ACTIVE_PLATFORM_FOCUS_EVENT, { ...payload, at: new Date() });\n// after\nawait emit(ACTIVE_PLATFORM_FOCUS_EVENT, { ...payload, at: Date.now() });","handlingStrategy":"try-catch","validationCode":"if (!isEmitPayloadSafe(payload)) {\n  console.warn('skip focus emit: payload not serializable');\n  return;\n}","typeGuard":"function isActivePlatformFocusPayload(v: unknown): v is ActivePlatformFocusPayload {\n  return isPlainObject(v) && typeof (v as { platform?: unknown }).platform === 'string';\n}","tryCatchPattern":"try {\n  await emit<ActivePlatformFocusPayload>(ACTIVE_PLATFORM_FOCUS_EVENT, payload);\n} catch (error) {\n  console.warn(`[account-sync] Failed to emit ${ACTIVE_PLATFORM_FOCUS_EVENT}:`, error);\n}","preventionTips":["Validate payload shape before emitting","Serialize dates as numbers/ISO strings","Gate emits on Tauri event API availability","Re-sync focus state on window focus events"],"tags":["tauri","event-emit","ipc"],"backgroundTag":"tauri-event-emit-failed","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}