Rails Event Store

Client Errors

When using Rails Event Store you have to be prepared for following errors:


Occurs when other writer has written to the same stream as we intended to and last stream version has changed:

client.publish(OrderPlaced.new, stream_name: 'Order$1', expected_version: 0)

expect do
  client.publish(OrderCompleted.new, stream_name: 'Order$1', expected_version: 0)
end.to raise_error(WrongExpectedEventVersion)

Second write to the stream should have happened with expected_version: 1 above.


Occurs when you're writing same event more than once.

order_placed = OrderPlaced.new
client.publish(order_placed, stream_name: 'Order$1', expected_version: 0)

expect do
  client.publish(order_placed, stream_name: 'Order$1', expected_version: 1)
end.to raise_error(WrongExpectedEventVersion)

If you want to have an event present in multiple streams, you have to link it with link.


Occurs when invalid exception_version is passed in append_to_stream, link_to_stream or publish. Valid values are Integer or one of :any, :none, :auto.

expect do
  client.append(OrderPlaced.new, stream_name: 'Order$1', expected_version: nil)
end.to raise_error(InvalidExpectedVersion)


Occurs when invalid stream_name is passed in any client method expecting it. Name must not be nil or empty string.

expect do
  client.append(OrderPlaced.new, stream_name: nil)
end.to raise_error(IncorrectStreamData)


Occurs when event of given id cannot be found. This can happen either when looking for particular event details via read_event or when reading stream, starting from given event.

none_such_id = SecureRandom.uuid
expect do
end.to raise_error(EventNotFound)


Occurs when reading a stream with invalid start parameter passed. Must not be nil or empty string.

expect do
end.to raise_error(InvalidPageStart)


Occurs when reading a stream with invalid to parameter passed. Must not be nil or empty string.

expect do
end.to raise_error(InvalidPageStop)


Occurs when expecting to read less than one event from a stream:

expect do
end.to raise_error(InvalidPageSize)


Occurs when given subscriber is nil.

expect do
  client.subscribe(nil, to: [OrderPlaced])
end.to raise_error(SubscriberNotExist)


Occurs when given subscriber is not a valid handler to given dispatcher.

subscriber = Object.new
expect do
  client.subscribe(subscriber, to: [OrderPlaced])
end.to raise_error(InvalidHandler)


Occurs when passing stream name of all when using RailsEventStoreActiveRecord of RubyEventStore::ROM repository. This stream name is used internally to implement global stream. Use dedicated global stream readers in order to read events from it.


Raised when event's data is not serializable by RubyEventStore::Mappers::Protobuf.