AshJido.Error (AshJido v1.0.0)

Copy Markdown View Source

Facade for converting Ash errors to Jido.Action.Error Splode-based errors.

This module provides utilities to transform Ash Framework error types into the Jido Action error system, preserving error details and providing consistent error handling across the Ash-Jido integration.

Summary

Functions

Extracts changeset-specific error information.

Extracts field-specific errors for validation feedback.

Extracts the list of underlying errors from an Ash error.

Converts an Ash error to a Jido.Action.Error.

Functions

extract_changeset_errors(ash_error)

@spec extract_changeset_errors(Exception.t()) :: [map()]

Extracts changeset-specific error information.

Returns a list of maps containing error type, message, and details for errors related to changesets or validations.

extract_field_errors(ash_error)

@spec extract_field_errors(Exception.t()) :: %{required(atom()) => [String.t()]}

Extracts field-specific errors for validation feedback.

Returns a map where keys are field names and values are lists of error messages for that field.

extract_underlying_errors(ash_error)

@spec extract_underlying_errors(Exception.t()) :: [Exception.t()]

Extracts the list of underlying errors from an Ash error.

Ash errors often wrap multiple underlying errors. This function extracts them for detailed error inspection.

from_ash(ash_error)

@spec from_ash(Exception.t()) :: Exception.t()

Converts an Ash error to a Jido.Action.Error.

Pattern matches on different Ash error types and converts them to appropriate Jido error constructors:

The original Ash error is preserved in the details map under the :ash_error key.

Examples

iex> AshJido.Error.from_ash(%Ash.Error.Invalid{errors: []})
%Jido.Action.Error.InvalidInputError{...}

iex> AshJido.Error.from_ash(%Ash.Error.Forbidden{errors: []})
%Jido.Action.Error.ExecutionFailureError{...}