error v0.4.2 Error View Source

Model domain and infrastructure errors as regular data.

Link to this section Summary

Functions

Extract the cause of an error (of type Error.t()).

Return the map of detailed information supplied at Error creation.

Create a domain error, with a reason and optional details.

Flattens the given error and all its nested causes into a list.

Create an infra error, with a reason and optional details.

A guard to use in order to pattern match errors. Will match on Domain errors, but not Infra errors.

A guard to use in order to pattern match errors. Will match on both Infra and Domain Errors.

A guard to use in order to pattern match errors. Will match on Infra errors, but not Domain errors.

Determine whether a given Error is a domain or infra error.

Map a function on the details map in an Error.

Return the reason the Error was created with.

Extracts the root cause of the given error.

Convert an Error to an Elixir map.

Wrap a higher-level error 'on top' of a lower-level error.

Link to this section Types

Link to this type

domain(a)

View Source
domain(a) :: %Error.DomainError{caused_by: term(), details: a, reason: reason()}
Link to this type

infra(a)

View Source
infra(a) :: %Error.InfraError{caused_by: term(), details: a, reason: reason()}
Link to this type

kind()

View Source
kind() :: :domain | :infra
Link to this type

t(a)

View Source
t(a) ::
  %Error.DomainError{caused_by: term(), details: a, reason: reason()}
  | %Error.InfraError{caused_by: term(), details: a, reason: reason()}

Link to this section Functions

Link to this function

caused_by(arg1)

View Source
caused_by(t(a)) :: FE.Maybe.t(t(a)) when a: any()

Extract the cause of an error (of type Error.t()).

Think of this as inspecting deeper into the stack trace.

Link to this function

details(arg1)

View Source
details(t(a)) :: a when a: any()

Return the map of detailed information supplied at Error creation.

Link to this function

domain(reason, details \\ %{})

View Source
domain(atom(), a) :: t(a) when a: any()

Create a domain error, with a reason and optional details.

Link to this function

flatten(e)

View Source
flatten(t(a)) :: [t(a)] when a: any()

Flattens the given error and all its nested causes into a list.

The given error is always the first element of resulting list.

Link to this function

infra(reason, details \\ %{})

View Source
infra(atom(), a) :: t(a) when a: any()

Create an infra error, with a reason and optional details.

Link to this macro

is_domain_error(x)

View Source (macro)

A guard to use in order to pattern match errors. Will match on Domain errors, but not Infra errors.

A guard to use in order to pattern match errors. Will match on both Infra and Domain Errors.

Link to this macro

is_infra_error(x)

View Source (macro)

A guard to use in order to pattern match errors. Will match on Infra errors, but not Domain errors.

Determine whether a given Error is a domain or infra error.

Link to this function

map_details(error, f)

View Source
map_details(t(a), (a -> b)) :: t(b) when a: any(), b: any()

Map a function on the details map in an Error.

Useful for adding extra details, modifying exisint ones, or removing them.

Link to this function

reason(arg1)

View Source
reason(t()) :: reason()

Return the reason the Error was created with.

Link to this function

root_cause(e)

View Source
root_cause(t(a)) :: t(a) when a: any()

Extracts the root cause of the given error.

The root cause of an error without an underlying cause is the error itself.

Convert an Error to an Elixir map.

Link to this function

wrap(inner, outer)

View Source
wrap(t(a), t(a)) :: t(a) when a: any()

Wrap a higher-level error 'on top' of a lower-level error.

Think of this as a stack trace, but in domain-model terms.