DoubleEntryLedger.Command.TransferErrors (double_entry_ledger v0.3.0)

View Source

Provides functions to extract and manipulate error information from Ecto changesets.

This module handles the propagation of validation errors between different schema types in the double entry ledger system. It ensures that when validation fails at any level (accounts, transactions, commands), the errors are properly mapped back to the appropriate command map structure for consistent error handling and reporting.

The main functionality includes:

  • Transferring errors from account changesets to command maps
  • Transferring errors from command changesets to command maps
  • Transferring errors from transaction changesets to command maps
  • Extracting and formatting error messages from changesets

Summary

Types

Union type representing either an AccountCommandMap or TransactionCommandMap.

Union of command-related types used for parameterizing changeset specs when transferring errors. This can be a command map or its payload type.

Union type representing either AccountData or TransactionData.

Functions

Transfers validation errors from an account changeset to a command map changeset.

Maps command validation errors to a command map changeset.

Transfers transaction validation errors to a command map payload changeset.

Returns errors grouped by field as a map of lists of {message_template, opts} tuples.

Types

command_map()

Union type representing either an AccountCommandMap or TransactionCommandMap.

These are the two main command map types that can contain validation errors that need to be transferred and properly attributed.

command_related()

@type command_related() :: command_map() | payload()

Union of command-related types used for parameterizing changeset specs when transferring errors. This can be a command map or its payload type.

payload()

Union type representing either AccountData or TransactionData.

Functions

from_account_to_command_map_payload(command_map, account_changeset)

Transfers validation errors from an account changeset to a command map changeset.

When account validation fails during command processing, this function ensures those errors are properly reflected in the command map structure, maintaining full error context and attribution.

Parameters

  • command_map: The command map that contains the account data
  • account_changeset: Account changeset containing validation errors

Returns

  • Ecto.Changeset.t(): Command map changeset with propagated account errors

from_command_to_command_map(command_map, command_changeset)

@spec from_command_to_command_map(em, Ecto.Changeset.t(DoubleEntryLedger.Command.t())) ::
  Ecto.Changeset.t(em)
when em: command_map()

Maps command validation errors to a command map changeset.

When a command fails validation during creation or update, this function ensures those errors are properly reflected in the command map structure, maintaining full error context and attribution.

Parameters

  • command_map: The original command map
  • command_changeset: Command changeset containing validation errors

Returns

  • Ecto.Changeset.t(): Command map changeset with propagated errors

from_idempotency_key_to_command_map(command_map, ik_changeset)

from_transaction_to_command_map_payload(command_map, trx_changeset)

Transfers transaction validation errors to a command map payload changeset.

The returned command map changeset embeds a payload changeset that includes the propagated transaction errors (e.g., status and entry-level errors).

get_all_errors_with_opts(changeset)

Returns errors grouped by field as a map of lists of {message_template, opts} tuples.

Messages are not interpolated; templates and their options are preserved for downstream formatting, translation, or logging.

has_error?(changeset, field, msg, opts)