Exception: Funes::InvalidMaterializationState

Inherits:
StandardError
  • Object
show all
Defined in:
lib/funes/invalid_materialization_state.rb

Overview

Raised when a projection configured with ‘persist_materialization_model_with` produces an invalid materialization state.

When a projection declares a custom persistence method via ‘persist_materialization_model_with`, Funes still validates the materialization (via `state.valid?`) before delegating the write. If validation fails, this exception is raised and the custom persist method is not invoked.

The failed materialization is exposed via ‘#record`, mirroring the ergonomics of `ActiveRecord::RecordInvalid` — but without coupling the custom-persist path to ActiveRecord. Like any unrescued exception, it propagates out of `materialize!` and rolls back any enclosing `ActiveRecord::Base.transaction`, which is the desired behaviour for transactional projections.

Examples:

Handling an invalid materialization state

begin
  YourProjection.materialize!(events, "some-id", at: Time.current)
rescue Funes::InvalidMaterializationState => e
  Rails.logger.error "Invalid materialization: #{e.message}"
  e.record.errors.full_messages # the validation errors on the materialization
end

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ InvalidMaterializationState

Returns a new instance of InvalidMaterializationState.



26
27
28
29
# File 'lib/funes/invalid_materialization_state.rb', line 26

def initialize(record)
  @record = record
  super("Invalid materialization state: #{record.errors.full_messages.to_sentence}")
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



24
25
26
# File 'lib/funes/invalid_materialization_state.rb', line 24

def record
  @record
end