Predicator.Errors.TypeMismatchError (predicator v2.2.0)

View Source

Error struct for type mismatch errors in Predicator evaluation.

This error occurs when an operation receives values of incorrect types, such as trying to perform arithmetic on strings or logical operations on integers.

Fields

  • message - Human-readable error description
  • expected - The type that was expected (e.g., :integer, :boolean)
  • got - The actual type(s) received (single type or tuple for binary operations)
  • values - The actual value(s) that caused the error (optional, for debugging)
  • operation - The operation that failed (e.g., :add, :logical_and)

Examples

%Predicator.Errors.TypeMismatchError{
  message: "Arithmetic add requires integers, got "hello" (string) and 5 (integer)",
  expected: :integer,
  got: {:string, :integer},
  values: {"hello", 5},
  operation: :add
}

%Predicator.Errors.TypeMismatchError{
  message: "Unary minus requires an integer, got "text" (string)",
  expected: :integer,
  got: :string,
  values: "text",
  operation: :unary_minus
}

Summary

Functions

Creates a type mismatch error for binary operations.

Creates a type mismatch error for unary operations.

Types

t()

@type t() :: %Predicator.Errors.TypeMismatchError{
  expected: atom(),
  got: atom() | {atom(), atom()},
  message: binary(),
  operation: atom(),
  values: term()
}

Functions

binary(operation, expected, arg1, arg2)

@spec binary(atom(), atom(), {atom(), atom()}, {any(), any()}) :: t()

Creates a type mismatch error for binary operations.

unary(operation, expected, got, value)

@spec unary(atom(), atom(), atom(), any()) :: t()

Creates a type mismatch error for unary operations.