Back to Academy
coding principles
Fail Fast
The Fail Fast principle states that a system should immediately report any condition that is likely to lead to failure. Rather than continuing with invalid data and producing mysterious errors downstream, validate inputs and preconditions at the earliest possible point and throw clear, actionable errors. This makes bugs easier to locate because the error occurs close to the root cause rather than manifesting as a confusing side effect far away in the code.
Use Cases
- •Validating function arguments at the top of a function before doing any work
- •Checking configuration values at application startup rather than when they are first used at runtime
- •Using strict type checking and assertions during development to catch errors early
- •Validating API request payloads at the controller level before passing data to business logic
Visualization
Implementation
Output
Click "Run Code" to see output...