Centralized error handling for Jido.Browser using Splode.
Error classes are for classification; concrete ...Error structs are for raising/matching.
Summary
Functions
Creates an adapter error with the given message and optional details.
Creates an element error for the given action, selector, and reason.
Creates an invalid input/state error with the given message and optional details.
Creates a navigation error for the given URL and reason.
Creates a timeout error for the given operation and timeout duration.
Traverses errors, calling fun for each leaf error, and returns a nested
map of results grouped by each error's path.
Raises an error if the result is an error, otherwise returns the result
Types
@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() }
@type class_module() ::
Timeout | Element | Navigation | Adapter | Invalid | Splode.Error.Unknown
@type error_class() ::
:timeout | :element | :navigation | :adapter | :invalid | :unknown
@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
@spec adapter_error(String.t(), map()) :: Jido.Browser.Error.AdapterError.t()
Creates an adapter error with the given message and optional details.
@spec element_error(String.t(), String.t(), term()) :: Jido.Browser.Error.ElementError.t()
Creates an element error for the given action, selector, and reason.
@spec invalid_error(String.t(), map()) :: Jido.Browser.Error.InvalidError.t()
Creates an invalid input/state error with the given message and optional details.
@spec timeout_error(String.t(), non_neg_integer()) :: Jido.Browser.Error.TimeoutError.t()
Creates a timeout error for the given operation and timeout duration.
Traverses errors, calling fun for each leaf error, and returns a nested
map of results grouped by each error's path.
See Splode.traverse_errors/2 for full documentation.
Example
iex> Elixir.Jido.Browser.Error.traverse_errors(error, fn error ->
...> Exception.message(error)
...> end)
%{name: ["name is required"]}
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 toto_error/2when 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}
endend
def function!(arg) do
YourErrors.unwrap!(function(arg))end