Skip to main content

Function: validateServicePayload()

function validateServicePayload<T>(
validator: Validator<T>,
value: unknown,
context: ValidationContext
): T;

Defined in: src/services/utils/validation.ts:237

Validates a payload using a shared Zod schema and unwraps the typed result.

Type Parametersโ€‹

Tโ€‹

T

Parametersโ€‹

validatorโ€‹

Validator<T>

Function returning a safeParse-style result.

valueโ€‹

unknown

Raw value to validate.

contextโ€‹

ValidationContext

Service/operation context used to format errors.

Returnsโ€‹

T

Parsed data when validation succeeds.

Remarksโ€‹

This helper is intentionally opinionated about the resulting error messages, following the pattern used by data-oriented services:

  • When the validator throws, the error message uses the form:

    • "[ServiceName] <operation> threw during validation".
  • When validation fails, the message uses the form:

    • "[ServiceName] <operation> returned invalid payload: <issues>".

In both cases, the original error (validator exception or Zod error) is attached via Error.cause. Callers are expected to allow these errors to propagate into the existing service wrappers (for example getIpcServiceHelpers().wrap()), which handle logging and error surfacing.

Throwsโ€‹

Error when validation fails or the validator itself throws.