Module: Axn::Internal::ContractErrorHandling

Defined in:
lib/axn/internal/contract_error_handling.rb

Class Method Summary collapse

Class Method Details

.with_contract_error_handling(exception_class:, message:, field_identifier:) { ... } ⇒ Object

Executes a block, allowing fail! and done! to propagate normally, but wrapping other StandardErrors in the specified exception class.

Parameters:

  • exception_class (Class)

    The exception class to wrap errors in

  • message (String, Proc)

    Error message or proc that takes (field_identifier, error)

  • field_identifier (String)

    Identifier for the field (for error messages)

Yields:

  • The block to execute

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/axn/internal/contract_error_handling.rb', line 18

def with_contract_error_handling(exception_class:, message:, field_identifier:)
  yield
rescue Axn::Failure, Axn::Internal::EarlyCompletion => e
  raise e # Re-raise control flow exceptions without wrapping
rescue StandardError => e
  error_message = if message.is_a?(Proc)
                    message.call(field_identifier, e)
                  else
                    format(message, field_identifier, e.message)
                  end
  raise exception_class, error_message, cause: e
end