Exception: Statecraft::StaleTransition

Inherits:
TransitionConflict show all
Defined in:
lib/statecraft/errors.rb

Overview

The refusal of a seen: token: the snapshot the caller acted on is not the row's version — or could not be read at all, which is the same answer with nothing to compare (expected_version stays nil). A subclass of TransitionConflict, so existing rescues keep catching it; controllers map it to 409 specifically.

Instance Attribute Summary collapse

Attributes inherited from TransitionConflict

#expected_from, #record

Instance Method Summary collapse

Constructor Details

#initialize(record:, expected_from:, expected_version:, seen:) ⇒ StaleTransition

Returns a new instance of StaleTransition.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/statecraft/errors.rb', line 57

def initialize(record:, expected_from:, expected_version:, seen:)
  @expected_version = expected_version
  @seen = seen
  reason =
    if expected_version.nil?
      "the token #{seen.inspect} is not a readable version"
    else
      "the caller saw version #{seen.inspect}, but the row has moved on"
    end
  super(record: record, expected_from: expected_from,
        message: "stale transition for #{record.class.name}##{record.id}: #{reason}")
end

Instance Attribute Details

#expected_versionObject (readonly)

Returns the value of attribute expected_version.



55
56
57
# File 'lib/statecraft/errors.rb', line 55

def expected_version
  @expected_version
end

#seenObject (readonly)

Returns the value of attribute seen.



55
56
57
# File 'lib/statecraft/errors.rb', line 55

def seen
  @seen
end