Sourcing::X::OptimisticLocked

Exception thrown when optimistic locking fails during event emission. Indicates that another process has modified the aggregate state since the expected version was read.

Attributes

AttributeTypeDescription
$.typeMu:UThe aggregation type that failed to emit
$.idsHashThe projection IDs of the aggregate instance
$.expected-versionIntThe version the command expected
$.actual-versionIntThe version actually found in the store

Message

The exception message includes all context for debugging:

<sourcing optimistic locked: type=BankAccount, ids={:account-id(1)}, expected-version=2, actual-version=3>

When It's Thrown

Handling the Exception

try {
    $account.withdraw(100);
    CATCH {
        when Sourcing::X::OptimisticLocked {
            say "Concurrent modification detected";
            say "Expected version: ", .expected-version;
            say "Actual version:   ", .actual-version;
            # Retry manually or inform the user
        }
    }
}

See Also