Failure while reading or writing an ASDF file.
reason is a stable atom. message is the text Exception.message/1
returns. source is a path or :binary when the failure is tied to one
input. offset is a zero-based byte index. line and column are set
when the YAML parser reports them. format is always :asdf.
Raising the struct prints message. wrap/1 returns the tagged tuple
the rest of the library uses.
Examples
iex> {:error, error} = ASDF.Error.wrap(reason: :not_asdf, message: "bad", offset: 0, line: 1)
...> {error.reason, error.offset, error.line, error.format}
{:not_asdf, 0, 1, :asdf}
Summary
Types
@type t() :: %ASDF.Error{ __exception__: true, column: non_neg_integer() | nil, format: :asdf, line: pos_integer() | nil, message: String.t(), offset: non_neg_integer() | nil, reason: atom(), source: term() }
One failure.
:message— text shown when the error is raised:format— always:asdf:source— path or:binary, ornilwhen the failure has no input:offset— zero-based byte index, ornil:line— one-based YAML line, ornil:column— zero-based YAML column, ornil:reason— stable atom such as:not_asdfor:closed
Functions
Returns the error text.
error is an %ASDF.Error{}. Returns the :message binary.
This is the Exception callback used by raise/1.
Examples
iex> {:error, error} = ASDF.Error.wrap(message: "bad", reason: :io)
...> ASDF.Error.message(error)
"bad"
Builds {:error, %ASDF.Error{}} from attrs.
attrs is a keyword list of the struct fields. :message is required.
Unknown keys raise KeyError. Returns {:error, error} and does not
raise when the fields are valid.
Examples
iex> {:error, error} = ASDF.Error.wrap(reason: :not_asdf, message: "bad")
...> Exception.message(error)
"bad"
iex> raise ASDF.Error, message: "bad", reason: :not_asdf
** (ASDF.Error) bad