TypeCheck v0.2.0 TypeCheck.TypeError exception View Source

Exception to be returned or raised when a value is not of the expected type.

This exception has two fields:

  • :raw, which will contain the problem tuple of the type check failure.
  • :message, which will contain a the humanly-readable representation of the raw problem_tuple

:message is constructed from :raw using the TypeCheck.TypeError.DefaultFormatter. (TODO at some point this might be configured to use your custom formatter instead)

Link to this section Summary

Types

The name of the particular check. Might be :no_match for simple types, but for more complex types that have multiple checks, it disambugates between them.

An extra map with any information related to the check that failed.

A problem_tuple contains all information about a failed type check.

The value that was passed in which failed the check.

t()

Any built-in TypeCheck struct (c.f. TypeCheck.Builtin.*), whose check(s) failed.

Link to this section Types

Specs

check_name() :: atom()

The name of the particular check. Might be :no_match for simple types, but for more complex types that have multiple checks, it disambugates between them.

For instance, for TypeCheck.Builtin.List we have :not_a_list, :different_length, and :element_error.

Specs

extra_information() :: %{optional(atom()) => any()}

An extra map with any information related to the check that failed.

For instance, if the check was a compound check, will contain the field problem: with the child problemtuple as well as :index or :key etc. to indicate _where in the compound structure the check failed.

Specs

A problem_tuple contains all information about a failed type check.

Specs

problematic_value() :: any()

The value that was passed in which failed the check.

It is included for the easy creation of value did not match y-style messages.

Specs

t() :: %TypeCheck.TypeError{
  __exception__: term(),
  message: String.t(),
  raw: problem_tuple()
}
Link to this type

type_checked_against()

View Source

Specs

type_checked_against() :: TypeCheck.Type.t()

Any built-in TypeCheck struct (c.f. TypeCheck.Builtin.*), whose check(s) failed.