Skip to content

ARCE0004: A command appends to Chronicle itself

Kind: call. Default severity: warning.

A command module that calls Chronicle.append* (on Chronicle or on a Chronicle.EventSequences module) appends on its own. The command should return what happened and let Arc append it.

When handle/2 returns {:append, event}, Arc appends it to the event source id in the command’s key: true field, maps concurrency and constraint violations to validation results the client can show, and uses the caller’s tenant. A direct append skips all of that, and the command also stops being a pure decision, which makes it harder to test.

def handle(%__MODULE__{} = command, ctx) do
Chronicle.append(command.id, %MyApp.Authors.AuthorRegistered{name: command.name})
{:ok, :registered}
end
def handle(%__MODULE__{} = command, _ctx),
do: {:append, %MyApp.Authors.AuthorRegistered{name: command.name}}

To append to another event source, return {event_source_id, event}. To also return a value to the client, return {:append, events, response}.

Return the events instead of appending them. If the append has to happen outside the command, move it into a reactor.