Validixir.Error (validixir v1.2.2)

Module containing data definition and functionality concerning an Error. An Error is a struct representing a concrete error in validation.

An Error consists of the following:

  • A candidate, representing the value that was validated
  • A message, describing the cause of the Error
  • A context in which the Error occured, e.g. a module or step

Link to this section Summary

Functions

Augments the context of an error.

Augments the message of an error.

Smart constructor of an error.

Overrides the context of an error.

Overrides the message of an error.

Link to this section Types

@type t() :: %Validixir.Error{candidate: term(), context: term(), message: term()}

Link to this section Functions

Link to this function

augment_context(error, additional_context)

@spec augment_context(t(), any()) :: t()

Augments the context of an error.

examples

Examples

iex> Validixir.Error.augment_context(Validixir.Error.make(12, :message, Context), NewContext)
%Validixir.Error{candidate: 12, message: :message, context: [NewContext, Context]}
Link to this function

augment_message(error, additional_message)

@spec augment_message(t(), any()) :: t()

Augments the message of an error.

examples

Examples

iex> Validixir.Error.augment_message(Validixir.Error.make(12, :message, Context), :new_message)
%Validixir.Error{candidate: 12, message: [:new_message, :message], context: Context}
Link to this function

make(candidate, message, context)

@spec make(any(), any(), any()) :: t()

Smart constructor of an error.

Link to this function

with_context(error, context)

@spec with_context(t(), any()) :: t()

Overrides the context of an error.

examples

Examples

iex> Validixir.Error.with_context(Validixir.Error.make(12, :message, Context), NewContext)
%Validixir.Error{candidate: 12, message: :message, context: NewContext}
Link to this function

with_message(error, message)

@spec with_message(t(), any()) :: t()

Overrides the message of an error.

examples

Examples

iex> Validixir.Error.with_message(Validixir.Error.make(12, :message, Context), :new_message)
%Validixir.Error{candidate: 12, message: :new_message, context: Context}