Dextrin.Error (Dextrin v0.3.0)

Copy Markdown View Source

One error struct for both the text and binary pipelines, so a caller never has to special-case which one produced it. Wraps Ichor.Error verbatim for the text side (including its caret-annotated context_lines, useful for CLI/log output); the binary side has no source text to annotate, so it only ever carries a message, a byte offset, and a stage.

Also the channel for schema-violation errors: those come back with stage: :action, the same stage Ichor.Error already uses for Ichor.Actions-level failures (a handle_rule/3/handle_token/3 callback returning {:error, _}) — so a schema violation and a syntax error are indistinguishable by shape alone, and a caller only ever needs to check {:error, %Dextrin.Error{}}.

Summary

Types

What kind of error this is, as DXN.md §5 names it — "syntax", "binary", "encode/unsupported", "schema/missing-field", ... — which every conforming implementation exposes, so the conformance suite can compare errors across languages without comparing messages. nil where no category has been assigned yet.

t()

Functions

An error raised outside the parsers — a schema violation, a value with no DXN meaning — with its DXN.md §5 category, when it has one.

An Ichor error, as a Dextrin.Error. One that carries a Dextrin.Error in its data -- an action's own refusal, with its own category -- is that error, with the Ichor error kept for its position; any other is a syntax error.

What a text parse refused with -- one Ichor error or several -- as Dextrin.Errors, through from_ichor/1.

Types

category()

@type category() :: String.t() | nil

What kind of error this is, as DXN.md §5 names it — "syntax", "binary", "encode/unsupported", "schema/missing-field", ... — which every conforming implementation exposes, so the conformance suite can compare errors across languages without comparing messages. nil where no category has been assigned yet.

stage()

@type stage() :: Ichor.Error.stage() | :binary

t()

@type t() :: %Dextrin.Error{
  byte_offset: non_neg_integer() | nil,
  category: category(),
  ichor_error: Ichor.Error.t() | nil,
  message: String.t(),
  stage: stage()
}

Functions

action(message, category \\ nil)

@spec action(String.t(), category()) :: t()

An error raised outside the parsers — a schema violation, a value with no DXN meaning — with its DXN.md §5 category, when it has one.

binary(message, byte_offset \\ nil)

@spec binary(String.t(), non_neg_integer() | nil) :: t()

format(error)

@spec format(t()) :: String.t()

from_ichor(err)

@spec from_ichor(Ichor.Error.t()) :: t()

An Ichor error, as a Dextrin.Error. One that carries a Dextrin.Error in its data -- an action's own refusal, with its own category -- is that error, with the Ichor error kept for its position; any other is a syntax error.

from_parse(errors)

@spec from_parse(Ichor.Error.t() | [Ichor.Error.t()]) :: t() | [t()]

What a text parse refused with -- one Ichor error or several -- as Dextrin.Errors, through from_ichor/1.