Exdantic.Error (exdantic v0.0.2)

View Source

Structured error representation for Exdantic validation errors.

Summary

Functions

Formats an error into a human-readable string.

Creates a new validation error.

Types

t()

@type t() :: %Exdantic.Error{
  code: atom(),
  message: String.t(),
  path: [atom() | String.t()]
}

Functions

format(error)

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

Formats an error into a human-readable string.

Examples

iex> error = %Exdantic.Error{path: [:user, :email], code: :format, message: "invalid format"}
iex> Exdantic.Error.format(error)
"user.email: invalid format"

iex> error = %Exdantic.Error{path: [], code: :type, message: "expected string"}
iex> Exdantic.Error.format(error)
": expected string"

new(path, code, message)

@spec new([atom() | String.t()] | atom() | String.t(), atom(), String.t()) :: t()

Creates a new validation error.

Parameters

  • path - Path to the field that caused the error
  • code - Error code identifying the type of error
  • message - Human-readable error message

Examples

iex> Exdantic.Error.new([:user, :email], :format, "invalid email format")
%Exdantic.Error{path: [:user, :email], code: :format, message: "invalid email format"}

iex> Exdantic.Error.new(:name, :required, "field is required")
%Exdantic.Error{path: [:name], code: :required, message: "field is required"}