Predicator.Errors.LocationError (predicator v3.7.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. It also covers the write-time failures of Predicator.ContextLocation.put/3.

Error Types

Resolution failures:

  • :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

Write failures:

  • :not_a_container - Path traverses a value that is neither a map nor a list
  • :invalid_index - List index in the path is out of range (negative)

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 an out-of-range list index in a location path.

Creates a LocationError for invalid bracket key types.

Creates a LocationError for invalid or unknown AST node types.

Creates a LocationError for assignment through a non-container value.

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
  | :not_a_container
  | :invalid_index

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_index(location, index)

@spec invalid_index(binary(), integer()) :: t()

Creates a LocationError for an out-of-range list index in a location path.

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_a_container(location, segment, value)

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

Creates a LocationError for assignment through a non-container value.

Used when a location path traverses a value that is neither a map nor a list, so intermediate structure cannot be created without destroying existing data.

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.