ExDatalog.Validator.Error (ExDatalog v0.2.0)

Copy Markdown View Source

Structured validation error types for ExDatalog programs.

Every error is a %ExDatalog.Validator.Error{} struct with:

  • kind — a machine-readable atom identifying the error category.
  • context — a map with error-specific context (relation, variable, rule index, etc.).
  • message — a human-readable description.

Error Kinds

KindPhaseDescription
:arity_mismatch1Fact or atom term count differs from relation arity
:undefined_relation1Reference to a relation not declared in the program
:invalid_term1A term is not a valid ExDatalog.Term.t()
:duplicate_relation1A relation is declared more than once
:unsafe_variable2A head variable does not appear in any positive body atom
:range_restriction2A variable in a constraint is not bound by positive body atoms
:unstratified_negation2A negative edge appears in a dependency cycle
:unbound_constraint_variable2A constraint references a variable not yet bound
:invalid_body_literal1A body literal is not {:positive, atom} or {:negative, atom}

Examples

iex> ExDatalog.Validator.Error.new(:undefined_relation, %{relation: "parent", rule_index: 0}, "rule 0 references undefined relation \"parent\"")
%ExDatalog.Validator.Error{
  kind: :undefined_relation,
  context: %{relation: "parent", rule_index: 0},
  message: "rule 0 references undefined relation \"parent\""
}

Summary

Functions

Constructs a new validation error.

Types

kind()

@type kind() ::
  :arity_mismatch
  | :undefined_relation
  | :invalid_term
  | :duplicate_relation
  | :unsafe_variable
  | :range_restriction
  | :unstratified_negation
  | :unbound_constraint_variable
  | :invalid_body_literal
  | :wildcard_in_head

t()

@type t() :: %ExDatalog.Validator.Error{
  context: map(),
  kind: kind(),
  message: String.t()
}

Functions

new(kind, context, message)

@spec new(kind(), map(), String.t()) :: t()

Constructs a new validation error.

Examples

iex> ExDatalog.Validator.Error.new(:arity_mismatch, %{relation: "parent", expected: 2, got: 1}, "arity mismatch")
%ExDatalog.Validator.Error{
  kind: :arity_mismatch,
  context: %{relation: "parent", expected: 2, got: 1},
  message: "arity mismatch"
}