/** * Generic IPC handler wrapper — standardizes error handling and logging. * * Creates a domain-specific wrapper that catches errors, logs them, * and returns IpcResult for consistent renderer-side handling. */ import { addMainBreadcrumb } from '@main/sentry'; import { createLogger } from '@shared/utils/logger'; import type { IpcResult } from '@shared/types/ipc'; export function createIpcWrapper(logPrefix: string) { const log = createLogger(logPrefix); return async function wrap(operation: string, fn: () => Promise): Promise> { addMainBreadcrumb('ipc', `${logPrefix}:${operation}`); try { const data = await fn(); return { success: true, data }; } catch (error) { const message = error instanceof Error ? error.message : String(error); log.error(`handler error [${operation}]:`, message); return { success: false, error: message }; } }; }