Reactor.Error (reactor v0.12.1)

View Source

Uses splode to manage various classes of error.

Summary

Functions

Convenience wrapper around use Splode.Error

Recursively searches through nested reactor errors for the first instance of the provided module.

Recursively searches through nested reactor errors and returns any errors which match the provided module name.

Raises an error if the result is an error, otherwise returns the result

Types

class()

@type class() :: %{
  :__struct__ => class_module(),
  :__exception__ => true,
  :errors => [t()],
  :class => error_class(),
  :bread_crumbs => [String.t()],
  :vars => Keyword.t(),
  :stacktrace => Splode.Stacktrace.t() | nil,
  :context => map(),
  optional(atom()) => any()
}

class_module()

@type class_module() ::
  Reactor.Error.Validation
  | Reactor.Error.Unknown
  | Reactor.Error.Invalid
  | Reactor.Error.Internal

error_class()

@type error_class() :: :validation | :unknown | :invalid | :reactor

t()

@type t() :: %{
  :__struct__ => module(),
  :__exception__ => true,
  :class => error_class(),
  :bread_crumbs => [String.t()],
  :vars => Keyword.t(),
  :stacktrace => Splode.Stacktrace.t() | nil,
  :context => map(),
  optional(atom()) => any()
}

Functions

__using__(opts)

(macro)
@spec __using__(keyword()) :: Macro.output()

Convenience wrapper around use Splode.Error

fetch_error(error, module)

@spec fetch_error(Exception.t(), module()) :: {:ok, Exception.t()} | :error

Recursively searches through nested reactor errors for the first instance of the provided module.

find_errors(error, module)

@spec find_errors(Exception.t(), module()) :: [Exception.t()]

Recursively searches through nested reactor errors and returns any errors which match the provided module name.

splode_error?(arg1, splode)

unwrap!(result, opts \\ nil)

Raises an error if the result is an error, otherwise returns the result

Alternatively, you can use the defsplode macro, which does this automatically.

Options

  • :error_opts - Options to pass to to_error/2 when converting the returned error
  • :unknown_error_opts - Options to pass to the unknown error if the function returns only :error. not necessary if your function always returns {:error, error}.

Examples

def function(arg) do

case do_something(arg) do
  :success -> :ok
  {:success, result} -> {:ok, result}
  {:error, error} -> {:error, error}
end

end

def function!(arg) do

YourErrors.unwrap!(function(arg))

end