Macaw.Format.Error exception (macaw_format v0.1.0)

Copy Markdown View Source

What every ! twin raises (spec/00 §3): its value twin's {:error, reason}, with the reason's term kept and its words for the message.

reason is the term exactly as the twin answers it, a list of {path, reason} faults or one bare reason, so a caller that catches nothing still reads the terms in a crash report, and a test asserts them without parsing words:

iex> error = Macaw.Format.Error.exception(reason: [{[], {:width, 1024}}], what: "not a format")
iex> {error.reason, Exception.message(error)}
{[{[], {:width, 1024}}], "not a format: value: is wider than 1024 characters, the most a format writes"}

exception/1 takes reason: and words it with macaw_base's Macaw.Base.Fault.sentence/2, passing root: along. The words are the caller's words: first, a function or a list of them each answering nil for a reason it doesn't word, then format's own, Macaw.Format.words/1, then macaw_base's general words. what: names what the input is not, and starts the message:

iex> Exception.message(Macaw.Format.Error.exception(reason: {:type, :pattern}, what: "not a time format"))
"not a time format: must be a strftime pattern, a string"

Summary

Types

exception/1's options.

t()

Types

option()

@type option() ::
  {:reason, term()}
  | {:what, String.t()}
  | {:root, String.t()}
  | {:words, Macaw.Base.Fault.words() | [Macaw.Base.Fault.words()]}

exception/1's options.

t()

@type t() :: %Macaw.Format.Error{
  __exception__: term(),
  message: String.t(),
  reason: term()
}