Forja.ValidationError exception (Forja v0.4.0)

View Source

Struct representing a payload validation failure.

Returned by Forja.emit/3 and Forja.emit_multi/4 when a schema module rejects the payload. Wraps validation errors in a Forja-owned type so callers never need to depend on the underlying validation library.

Fields

  • :type - The event type (string or schema module) that failed validation
  • :errors - List of normalized error maps with :field, :code, and :message
  • :message - Human-readable summary

Example

case Forja.emit(:app, MyEvent, payload: %{bad: true}) do
  {:ok, event} -> event
  {:error, %Forja.ValidationError{errors: errors}} ->
    Enum.map(errors, & &1.message)
end

Summary

Functions

Builds a %Forja.ValidationError{} from a type and a list of raw validation errors.

Types

error()

@type error() :: %{field: atom() | nil, code: atom(), message: String.t()}

t()

@type t() :: %Forja.ValidationError{
  __exception__: true,
  errors: [error()],
  message: String.t(),
  type: String.t() | module()
}

Functions

new(type, raw_errors)

@spec new(String.t() | module(), list()) :: t()

Builds a %Forja.ValidationError{} from a type and a list of raw validation errors.