Splode error hierarchy for Zvex.
Maps zvec C error codes to structured Elixir errors. Every error is a standard Elixir exception and belongs to one of six classes:
| Class | Errors | Meaning |
|---|---|---|
:invalid | Argument, FailedPrecondition | Bad input or unmet precondition |
:not_found | NotFound | Requested resource does not exist |
:conflict | AlreadyExists | Resource already exists |
:unavailable | PermissionDenied, ResourceExhausted, Unavailable, NotSupported | Temporary or permanent inability to perform the operation |
:internal | InternalError | Unexpected error in the native layer |
:unknown | Unknown | Unclassified error |
All errors carry a human-readable :message field.
Summary
Functions
Translates a NIF return value into a Splode error or passthrough.
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() ::
Zvex.Error.Unknown
| Zvex.Error.Internal
| Zvex.Error.Unavailable
| Zvex.Error.Conflict
| Zvex.Error.NotFound
| Zvex.Error.Invalid
@type error_class() ::
:unknown | :internal | :unavailable | :conflict | :not_found | :invalid
@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
Translates a NIF return value into a Splode error or passthrough.
Accepts:
:ok->:ok{:ok, value}->{:ok, value}{:error, {code_atom, message_binary}}->{:error, %SplodeError{}}
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.Zvex.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