AshIntrospection.Rpc.Errors (AshIntrospection v0.3.0)

View Source

Central error processing module for RPC operations.

Handles error transformation, unwrapping, and formatting for clients. Uses the AshIntrospection.Rpc.Error protocol to extract minimal information from exceptions.

This is a shared module used by both AshTypescript and AshKotlinMultiplatform. Language-specific behavior is configured via the config parameter.

Summary

Functions

Unwraps nested error structures from Ash error classes.

Types

config()

@type config() :: %{
  optional(:output_field_formatter) => atom(),
  optional(:rpc_dsl_section) => atom(),
  optional(:field_formatter_module) => module(),
  optional(:format_field_for_client) => (atom(), module() | nil, atom() ->
                                           String.t())
}

Functions

to_errors(errors, domain \\ nil, resource \\ nil, action \\ nil, context \\ %{}, config \\ %{})

@spec to_errors(term(), module() | nil, module() | nil, atom() | nil, map(), config()) ::
  [map()]

Transforms errors into standardized RPC error responses.

Processes errors through the following pipeline:

  1. Convert to Ash error class using Ash.Error.to_error_class
  2. Unwrap nested error structures
  3. Transform via Error protocol
  4. Apply resource-level error handler (if configured)
  5. Apply domain-level error handler (if configured)
  6. Interpolate variables into messages

Parameters

  • errors - The error(s) to transform
  • domain - The domain module (optional)
  • resource - The resource module (optional)
  • action - The action name (optional)
  • context - Additional context map
  • config - Language-specific configuration (see type definition)

unwrap_errors(errors)

@spec unwrap_errors(term()) :: [term()]

Unwraps nested error structures from Ash error classes.