Error propagation philosophy

Error vs Boolean for a check

There are two common ways to indicate a successful check: either return a Boolean value or return an error.

The trade off really is:

  • error Are the multiple ways your caller may want handle a failure? this will add complexity but gives granularity in the type of failure, specifically it buys the caller optionality if they want to perform an action based on the failure.
  • bool Is there really only fail or pass? cheap, simple but leaves the caller with no way to understand why or handle different cases for the failure.

It really depends, personally I’m a fan of bool first and error only if the upper layer really should handle different errors (e.g., if they can continue with certain errors and not others). It reduces complexity.