Module: Axn::Internal::ContractErrorHandling
- Defined in:
- lib/axn/internal/contract_error_handling.rb
Class Method Summary collapse
-
._rendered_identifier(identifier) ⇒ Object
A declared name (or the text a caller composed from some) as a UTF-8 String this layer owns.
-
.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.
Class Method Details
._rendered_identifier(identifier) ⇒ Object
A declared name (or the text a caller composed from some) as a UTF-8 String this layer owns. Only the
format branch above needs it — a Proc message: receives the identifier as it came, and renders it
itself where it writes it into prose (see Internal::FieldConfig).
46 47 48 |
# File 'lib/axn/internal/contract_error_handling.rb', line 46 def _rendered_identifier(identifier) Axn::Internal::Rendering.value_rendering(identifier) || Axn::Internal::Rendering.class_name(identifier) end |
.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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/axn/internal/contract_error_handling.rb', line 23 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 = if .is_a?(Proc) .call(field_identifier, e) else # Both operands of the format go through the renderer, not just the exception's # message: the identifier is a declared NAME, so a UTF-8 message beside a Latin-1 # name raises `Encoding::CompatibilityError` out of `format` itself — the wrapper # reporting an encoding failure in place of the contract failure it exists to name. # Two raw operands in the same encoding joined fine, so rendering only one is # strictly worse than rendering neither. format(, _rendered_identifier(field_identifier), Axn::Internal::Rendering.(e)) end raise exception_class, , cause: e end |