March 2025
Intermediate to advanced
202 pages
4h 45m
English
Let’s take this example to the next step. The code you’ve written so far is actually fairly brittle. For example, the code can easily be broken with a divide by zero error:
| | iex(4)> evt2 = EventSourcedCalculator.V2.handle_command(%{value: -1}, |
| | ...(4)> %{cmd: :div, value: 0}) |
| | %{event_type: :value_divided, value: 0} |
| | iex(5)> state2 = EventSourcedCalculator.V2.handle_event(%{value: 9}, evt2) |
| | ** (ArithmeticError) bad argument in arithmetic expression |
| | es_calc_v2.exs:31: EventSourcedCalculator.V2.handle_event/2 |
Modeling errors and failure conditions is an enormous topic covered in detail later in the book, so for now, you’ll only handle a couple of easily managed cases. Create a third version ...
Read now
Unlock full access