The Error Monad¶
There are multiple ways to deal with errors in OCaml: exceptions,
option, etc., each approach has strengths and
weaknesses. However, in Octez we settle on one, single, uniform way of
dealing with errors: the error monad.
This is a tutorial for the error monad. It makes the following assumptions
You can read English.
You have a basic familiarity with OCaml.
You have a basic familiarity with Lwt (if not, this tutorial links to Lwt resources when it becomes necessary).
Other than that, each section of this tutorial can be understood using the information of previous sections, no additional information is necessary. Note, however, that most sections also make forward references along the lines of “more details on this later” or “alternatives are presented later”. During a first read, this foreshadowing is only useful in that it lets you know that the information is coming and that you can move on with a partial understanding. On subsequent reads, it helps putting things in context.
Note that the core of this tutorial focuses on error management in Octez. For a short section on error management in the protocol see Part 3 Working within the protocol.
- Part 1:
result, Lwt, and Lwt-
- The binding operator
- Aside: the
Error_monadmodule is opened everywhere
- Recovering from errors
- Mixing different kinds of errors
- Promises of results: Lwt and
- Converting errors of promises
- Wait! There is too much! What module am I supposed to open locally and what operators should I use?
- What’s an error?
- Wait! It was supposed to be “one single uniform way of dealing with errors”! What is this?
- META COMMENTARY
- Part 4: Appendices