ASDF.Error exception (asdf v0.1.0)

Copy Markdown View Source

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

t()

One failure.

Functions

Returns the error text.

Builds {:error, %ASDF.Error{}} from attrs.

Types

t()

@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, or nil when the failure has no input
  • :offset — zero-based byte index, or nil
  • :line — one-based YAML line, or nil
  • :column — zero-based YAML column, or nil
  • :reason — stable atom such as :not_asdf or :closed

Functions

message(exception)

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"

wrap(attrs)

@spec wrap(keyword()) :: {:error, t()}

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