Errors and nulls
Throw clear, typed errors instead of returning codes. Never return or pass null, and give every field a value unless absence is a real state.
- Required 6
- Recommended 1
Required
Throw exceptions instead of returning error codes
RequiredSignal 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.Never return null
RequiredCollections return empty, services use a Null Object, and lookups return one consistent "absent" value. A caller should never crash because it forgot a check.
Never pass null into a function
RequiredNever call a function with
nullto mean "use the default" or "skip this". Give the function a clear variant or an options object instead.Make fields required unless absence is real
RequiredEvery constructor argument and data object field is required and non-nullable, unless "not there" is a real state of the business.
Never swallow errors
RequiredNever catch an error and carry on as if nothing happened. Handle it, add context and rethrow it, or let it reach the edge.
Await every async call
RequiredAwait every promise, task or future, or hand it to code that handles its errors. A call that nobody waits for loses its errors without a trace.
Recommended
Use typed domain exceptions
RecommendedGive 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.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/errors-and-nulls.