Skip to main content

Function: createValidatedInvoker()

createValidatedInvoker<TChannel>(channel: TChannel, validateResult: (candidate: unknown) => SafeParseLike<IpcInvokeChannelResult<TChannel>>, options: ResultValidationOptions): (...args: IpcInvokeChannelParams<TChannel>) => Promise<IpcInvokeChannelResult<TChannel>>

Defined in: electron/preload/core/bridgeFactory.ts:680

Creates a typed IPC invoker that additionally validates the successful response payload.

Type Parameters

TChannel

TChannel extends keyof IpcInvokeChannelMap

Parameters

channel

TChannel

validateResult

(candidate: unknown) => SafeParseLike<IpcInvokeChannelResult<TChannel>>

options

ResultValidationOptions = {}

Returns

(...args: IpcInvokeChannelParams<TChannel>): Promise<IpcInvokeChannelResult<TChannel>>

Parameters

args

...IpcInvokeChannelParams<TChannel>

Returns

Promise<IpcInvokeChannelResult<TChannel>>

Remarks

The main process is generally trusted, but this adds defense-in-depth against malformed payloads caused by:

  • Handler bugs/regressions,
  • Database corruption producing invalid domain objects,
  • Version skew during development hot reload.

When validation fails, this helper:

  1. Logs a structured warning in preload diagnostics,
  2. Forwards a diagnostics report to the main process,
  3. Throws an IpcError so the renderer can surface the failure.