Predicator.Errors.LocationError (predicator v3.5.0)

View Source

Error struct for location expression validation failures.

This error is raised when attempting to resolve a location path for assignment operations, but the expression does not represent a valid assignable location.

Error Types

  • :not_assignable - Expression cannot be used as an assignment target
  • :invalid_node - Unknown or unsupported AST node type
  • :undefined_variable - Variable referenced in bracket key is not defined
  • :invalid_key - Bracket key is not a valid string or integer
  • :computed_key - Computed expressions cannot be used as assignment keys

Examples

# Cannot assign to literal values
%LocationError{
  type: :not_assignable,
  message: "Cannot assign to literal value",
  details: %{expression_type: "literal value", value: 42}
}

# Cannot assign to function calls
%LocationError{
  type: :not_assignable,
  message: "Cannot assign to function call",
  details: %{expression_type: "function call", value: "len"}
}

# Invalid bracket key type
%LocationError{
  type: :invalid_key,
  message: "Bracket key must be string or integer",
  details: %{key_type: "boolean", key_value: true}
}

Summary

Functions

Creates a LocationError for computed expressions used as bracket keys.

Creates a LocationError for invalid bracket key types.

Creates a LocationError for invalid or unknown AST node types.

Creates a LocationError for non-assignable expressions.

Creates a LocationError for undefined variables in bracket keys.

Types

error_type()

@type error_type() ::
  :not_assignable
  | :invalid_node
  | :undefined_variable
  | :invalid_key
  | :computed_key

t()

@type t() :: %Predicator.Errors.LocationError{
  details: map(),
  message: binary(),
  type: error_type()
}

Functions

computed_key(message, expression)

@spec computed_key(binary(), term()) :: t()

Creates a LocationError for computed expressions used as bracket keys.

invalid_key(message, key_value)

@spec invalid_key(binary(), term()) :: t()

Creates a LocationError for invalid bracket key types.

invalid_node(message, node)

@spec invalid_node(binary(), term()) :: t()

Creates a LocationError for invalid or unknown AST node types.

not_assignable(expression_type, value)

@spec not_assignable(binary(), term()) :: t()

Creates a LocationError for non-assignable expressions.

Used when an expression cannot be used as an assignment target (l-value).

undefined_variable(message, variable_name)

@spec undefined_variable(binary(), binary()) :: t()

Creates a LocationError for undefined variables in bracket keys.