DoubleEntryLedger.Command.TransferErrors (double_entry_ledger v0.3.0)
View SourceProvides 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
@type command_map() :: DoubleEntryLedger.Command.AccountCommandMap.t() | DoubleEntryLedger.Command.TransactionCommandMap.t()
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.
@type payload() :: DoubleEntryLedger.Command.AccountData.t() | DoubleEntryLedger.Command.TransactionData.t()
Union type representing either AccountData or TransactionData.
Functions
@spec from_account_to_command_map_payload( DoubleEntryLedger.Command.AccountCommandMap.t(), Ecto.Changeset.t(DoubleEntryLedger.Account.t()) ) :: Ecto.Changeset.t(DoubleEntryLedger.Command.AccountCommandMap.t())
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 dataaccount_changeset: Account changeset containing validation errors
Returns
Ecto.Changeset.t(): Command map changeset with propagated account errors
@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 mapcommand_changeset: Command changeset containing validation errors
Returns
Ecto.Changeset.t(): Command map changeset with propagated errors
@spec from_idempotency_key_to_command_map( DoubleEntryLedger.Command.TransactionCommandMap.t(), Ecto.Changeset.t(DoubleEntryLedger.Command.IdempotencyKey.t()) ) :: Ecto.Changeset.t(DoubleEntryLedger.Command.TransactionCommandMap.t())
@spec from_transaction_to_command_map_payload( DoubleEntryLedger.Command.TransactionCommandMap.t(), Ecto.Changeset.t(DoubleEntryLedger.Transaction.t()) ) :: Ecto.Changeset.t(DoubleEntryLedger.Command.TransactionCommandMap.t())
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).
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.