Skip to content

Errors

All custom error classes are exported from the main package.

import {
ConcurrencyError,
ValidationError,
EventValidationError,
CommandError,
InfiniteLoopError,
ProjectionReplayLoopError,
ProjectionEventHandlerExecutionError,
ProcessManagerEventHandlerExecutionError,
ReplaySkipError,
RefreshingSkipError,
} from '@requence/event-sourcing'

Thrown when an optimistic concurrency conflict is detected — i.e., the stream version has changed between when events were loaded and when new events were appended.

PropertyTypeDescription
messagestringIncludes stream name, ID, expected and actual versions.

Wraps any error thrown inside a command handler. Provides context about which aggregate root and command caused the error.

PropertyTypeDescription
aggregateRootTypestringThe aggregate root type name.
commandNamestringThe command that threw.
streamIdstringThe stream ID.
originalErrorTThe original error.

Thrown when a Zod schema validation fails (e.g., when loading a snapshot with an invalid shape).

PropertyTypeDescription
zodErrorz.ZodErrorThe underlying Zod error.

Extends ValidationError. Thrown when an event payload fails validation against its registered Zod schema before being appended.

Thrown when a process manager emits the same event that triggered it on the same stream — indicating a recursive event cycle.

Thrown when a projection event handler tries to replayUntil a position in the future (at or after the current event’s position).

PropertyTypeDescription
projection{ name, eventHandler }The projection name and handler.
eventOutputEventThe current event.

Wraps errors thrown inside a projection event handler.

PropertyTypeDescription
projectionstringThe projection name.
eventHandlerstringThe handler name (e.g., onUserCreated).
eventBaseOutputEventThe event being processed.
originalErrorTThe original error.

ProcessManagerEventHandlerExecutionError<T>

Section titled “ProcessManagerEventHandlerExecutionError<T>”

Wraps errors thrown inside a process manager event handler.

PropertyTypeDescription
processManagerstringThe process manager name.
eventHandlerstringThe handler name.
eventBaseOutputEventThe event being processed.
originalErrorTThe original error.

These errors are used internally for flow control during replay and refresh operations:

Throw inside a projection event handler during replay to silently skip the current event.

import { ReplaySkipError } from '@requence/event-sourcing'
projection.withEventHandlers({
async onUserCreated(event, { replaying }) {
if (replaying && someCondition) {
throw new ReplaySkipError()
}
// ...
},
})

Throw inside a process manager event handler during refresh to silently skip the current event.

import { RefreshingSkipError } from '@requence/event-sourcing'

A convenience helper that throws ReplaySkipError.

import { skipReplay } from '@requence/event-sourcing'

A convenience helper that throws RefreshingSkipError.

import { skipRefreshing } from '@requence/event-sourcing'