Structured CRAM error.
reason is one of a fixed set of atoms chosen by this library. It is never
created from bytes in a file. detail is a short explanation written by the
library. data holds safe integers and flags, not sequence bases.
Summary
Functions
Format the error for Exception.message/1 and raise/1.
Build an error struct without raising.
Types
@type t() :: %CRAM.Error{ __exception__: term(), data: map(), detail: String.t(), format: :cram, offset: non_neg_integer() | nil, path: Path.t() | nil, reason: atom() }
A CRAM error.
:format— always:cram:path— file path when the source has one, otherwisenil:offset— byte offset when one is known, otherwisenil:reason— fixed atom, never derived from file bytes:detail— short library text. Empty when there is nothing to add:data— small map of integers, names, or checksums. Not sequence basesiex> %CRAM.Error{reason: :truncated, detail: "file ended", offset: 4} ...> |> Map.get(:reason) :truncated
Functions
Format the error for Exception.message/1 and raise/1.
The text is cram, the path and offset when they are set, then the reason
and detail. An empty detail is omitted. Raising CRAM.Error uses this text.
iex> error = CRAM.Error.new(path: "example.cram", offset: 26, reason: :truncated, detail: "header ended")
iex> Exception.message(error)
"cram example.cram at offset 26: truncated: header ended"
iex> raise CRAM.Error, reason: :overflow, detail: "ITF-8 value is outside int32"
** (CRAM.Error) cram: overflow: ITF-8 value is outside int32
Build an error struct without raising.
attrs is a keyword list or a map of the struct fields. Unknown keys raise
KeyError. This function does not raise CRAM.Error.
iex> error = CRAM.Error.new(reason: :truncated, detail: "file ended", offset: 4)
iex> error.reason
:truncated