Ambiguous Errors Are the Mind Killer
Ambiguous errors are a pervasive issue in software development. These errors, which are represented opaquely, can be found everywhere. Examples include HTTP 500 Internal Server Error, -EINVAL, Status.INTERNAL, and {"status": "error"}. Despite being second-class citizens compared to successful return values, errors have significant consequences.
Boundaries exist between applications and libraries, the operating system, and remote services. These boundaries are powerful in hiding complexity behind simple contracts, but errors crossing boundaries require precise information to act upon. There are two problematic options when dealing with ambiguous errors: reverse-engineering them or treating errors as catastrophic.
Both approaches lead to problems, as ambiguous errors are viral and cause increased effort and blame. Even languages like Rust, with strong typed errors, are not immune. io::Error wraps the OS's errno, and NotFound errors from fs::remove_file are often treated as successes despite being considered failures. Typed errors should be part of the API, with new error variants considered breaking changes.
Errors should encode enough meaning to help callers understand and respond appropriately. Modal encountered a variation where reinforcement learning trainers need to understand how their software fails to account for errors. Adding error contracts to models helps trainers understand and react to errors, improving resilience to upstream failures.
Listing all errors from the leaves of an execution graph upwards clarifies the types of failures and helps improve software resilience.
Rewritten by urgent.news; may contain errors — check the original.
Source: amit.prasad.me