Scrutinex.Error (Scrutinex v0.2.0)

Copy Markdown View Source

Represents a single validation failure.

Fields

  • :row - zero-based row index where the error occurred
  • :column - column name as a string, or nil for cross-column checks
  • :check - atom identifying the check that failed (e.g. :required, :type, :number)
  • :message - human-readable message using %{key} interpolation placeholders (Ecto-style) so callers can substitute metadata values for i18n
  • :metadata - map of substitution values for the message (e.g. %{number: 10})
  • :value - the original value that failed validation, or nil

Summary

Functions

Interpolates metadata values into the message template.

Types

t()

@type t() :: %Scrutinex.Error{
  check: atom(),
  column: String.t() | nil,
  message: String.t(),
  metadata: map(),
  row: non_neg_integer() | nil,
  severity: :error | :warning,
  value: term()
}

Functions

format_message(error)

@spec format_message(t()) :: String.t()

Interpolates metadata values into the message template.

Examples

error = %Scrutinex.Error{message: "must be greater than %{number}", metadata: %{number: 0}, row: 0, check: :number}
Scrutinex.Error.format_message(error)
#=> "must be greater than 0"