# `ExDatalog.Validator.Error`
[🔗](https://github.com/thanos/ex_datalog/blob/v0.5.0/lib/ex_datalog/validator/error.ex#L1)

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

| Kind | Phase | Description |
|---|---|---|
| `:arity_mismatch` | 1 | Fact or atom term count differs from relation arity |
| `:undefined_relation` | 1 | Reference to a relation not declared in the program |
| `:invalid_term` | 1 | A term is not a valid `ExDatalog.Term.t()` |
| `:duplicate_relation` | 1 | A relation is declared more than once |
| `:unsafe_variable` | 2 | A head variable does not appear in any positive body atom |
| `:range_restriction` | 2 | A variable in a constraint is not bound by positive body atoms |
| `:unstratified_negation` | 2 | A negative edge appears in a dependency cycle |
| `:unbound_constraint_variable` | 2 | A constraint references a variable not yet bound |
| `:invalid_body_literal` | 1 | A body literal is not `{:positive, atom}` or `{:negative, atom}` |
| `:multiple_aggregates` | 2 | A rule contains more than one aggregate constraint |
| `:aggregate_in_recursion` | 2 | An aggregate appears in a self-recursive rule |
| `:unstratified_aggregate` | 2 | An aggregate's input relation is not in a strictly lower stratum |
| `:invalid_callback` | 2 | A callback references a missing module/function or wrong arity |

## 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\""
    }

# `kind`

```elixir
@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
  | :multiple_aggregates
  | :aggregate_in_recursion
  | :unstratified_aggregate
  | :invalid_callback
```

# `t`

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

# `new`

```elixir
@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"
    }

---

*Consult [api-reference.md](api-reference.md) for complete listing*
