Module: Castkit::Ext::Attribute::ErrorHandling

Included in:
Validation
Defined in:
lib/castkit/ext/attribute/error_handling.rb

Overview

Provides centralized handling of attribute casting and validation errors.

The behavior of each error is controlled by configuration flags in ‘Castkit.configuration`.

Constant Summary collapse

ERROR_OPTIONS =

Maps known error types to their handling behavior.

Each entry includes:

  • ‘:config` – the config flag that determines enforcement

  • ‘:message` – a lambda that generates an error message

  • ‘:error` – the error class to raise

Returns:

  • (Hash{Symbol => Hash})
{
  access: {
    config: :enforce_attribute_access,
    message: ->(_attr, mode:) { "invalid access mode `#{mode}`" },
    error: Castkit::AttributeError
  },
  unwrapped: {
    config: :enforce_unwrapped_prefix,
    message: ->(*_) { "prefix can only be used with unwrapped attribute" },
    error: Castkit::AttributeError
  },
  array_options: {
    config: :enforce_array_options,
    message: ->(*_) { "array attribute must specify `of:` type" },
    error: Castkit::AttributeError
  }
}.freeze