Errors and nulls
Signal failure with typed errors or results, not codes. Return empty lists instead of null, never swallow an error and release every resource you open.
- Required 5
- Recommended 4
- Avoid 1
Required
Never swallow errors
ARC-31Never catch an error and carry on as if nothing happened. Handle it, add context and rethrow it, or let it reach the edge.
Release every resource you open
ARC-32Close every file, connection, lock and handle with the language's scoped construct, so it is released on success and on error.
Cap every collection that grows with use
ARC-34Give every in-memory cache, queue, buffer and batch of parallel work a maximum size. Nothing in a long-running process may grow without a limit.
Never use assertions for checks production needs
ARC-69Write every check on input, permissions or state with an explicit condition that raises an error. Use
assertonly for facts that tests should catch, never for checks production depends on.Limit how deep code recurses on input
ARC-82Every recursive function that walks outside input stops at a fixed depth, such as 64 levels, and raises a typed error. Input never decides how deep the stack grows.
Recommended
Signal failure with an exception or a typed result instead of a code
ARC-26Signal failure with an exception or a typed result. Never return a magic value such as
-1,falseor an error string that callers must remember to check.Use typed domain exceptions
ARC-27Give each kind of failure its own exception type with a clear name and the data needed to handle it. Never throw a bare generic error with only a message.
Return empty collections and one agreed absent value instead of null
ARC-28Collections return empty, services use a Null Object, and lookups return one consistent "absent" value. A caller should never crash because it forgot a check.
Make fields required unless absence is valid
ARC-30Every constructor argument and data object field is required and non-nullable, unless "not there" is a valid state of the business.
Avoid
Passing null to mean a default
ARC-29Never call a function with
nullto mean "use the default" or "skip this". Give the function a clear variant or an options object instead.
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/errors-and-nulls">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.