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
- 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
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
- 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
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
- [account-sync] Failed to emit ${eventName}:
- [AntigravityInstalledVersionBadge] failed to load installed
- [AntigravityInstalledVersionBadge] failed to complete instal
- [WorkbuddyAutoCheckin] 监听后端签到配置事件失败:
- [WorkbuddyAutoCheckin] 读取后端签到日志失败:
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/df061cb1c0cec505.
Report an issue: GitHub.