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
@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.
@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.
@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.
@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:
Ash.Error.Invalid→ validation_errorAsh.Error.Forbidden→ execution_error with reason :forbiddenAsh.Error.Framework→ internal_errorAsh.Error.Unknown→ internal_error- Other exceptions → execution_error
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{...}