Exception raised when a language tag, unit identifier, or MF2 message cannot be parsed.
For MF2 message parse errors, the exception carries structured source
location information (:offset, :line, :column) describing where
in the input the parser failed. :line and :column are 1-indexed
and :offset is a 0-indexed byte offset into the input string. This
information is intended for tooling — editor integrations, language
servers, and CLI diagnostics — that need to map errors back to source
positions.
For other uses (language tag / unit identifier parsing) the location
fields may be nil.
The :reason field is a documented atom describing the parser
failure category. The :detail field optionally carries additional
context (for example, a NimbleParsec expectation string) and
:cause carries an underlying exception when a higher-level parser
has wrapped a lower-level one.
Summary
Functions
Computes 1-indexed line and column for a byte offset into input.
Types
@type reason() ::
:unexpected_trailing_input
| :unexpected_input
| :incomplete_input
| :invalid_message_format
@type t() :: %Localize.ParseError{ __exception__: true, cause: Exception.t() | nil, column: pos_integer() | nil, detail: String.t() | nil, input: String.t() | nil, line: pos_integer() | nil, offset: non_neg_integer() | nil, reason: reason() | nil, rest: String.t() | nil }
Functions
@spec line_column(String.t(), non_neg_integer()) :: {pos_integer(), pos_integer()}
Computes 1-indexed line and column for a byte offset into input.
Arguments
inputis the source string.offsetis a 0-indexed byte offset intoinput.
Returns
{line, column}where both are 1-indexed positive integers.If
offsetis out of bounds, returns the position of the last character (or{1, 1}for an empty input).
Examples
iex> Localize.ParseError.line_column("Hello\nworld", 0)
{1, 1}
iex> Localize.ParseError.line_column("Hello\nworld", 6)
{2, 1}
iex> Localize.ParseError.line_column("Hello\nworld", 9)
{2, 4}