Detect and halt on precondition failures before expensive operations begin. Validate inputs, permissions, and state upfront in CI/CD and automation workflows.
Validates preconditions like inputs, permissions, and state before expensive operations. Triggers in CI/CD workflows and automation to halt immediately on failures, preventing partial execution and wasted resources.
/plugin marketplace add adaptive-enforcement-lab/claude-skills/plugin install patterns@ael-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
examples.mdreference.mdscripts/example-1.mermaidscripts/example-2.yamlscripts/example-3.goscripts/example-4.mermaidscripts/example-5.goscripts/example-6.yamlscripts/example-7.goscripts/example-8.shFail fast is a design pattern that validates preconditions before executing expensive or irreversible operations. When validation fails, the system immediately reports the error rather than proceeding and failing later in an unpredictable state.
flowchart TD
subgraph validation[Validation Phase]
A[Request] --> B{Preconditions Met?}
end
subgraph execution[Execution Phase]
C[Execute Operation]
D[Success]
end
subgraph failure[Failure Phase]
E[Report Error]
F[No Side Effects]
end
B -->|Yes| C
C --> D
B -->|No| E
E --> F
%% Ghostty Hardcore Theme
style A fill:#65d9ef,color:#1b1d1e
style B fill:#fd971e,color:#1b1d1e
style C fill:#a7e22e,color:#1b1d1e
style D fill:#a7e22e,color:#1b1d1e
style E fill:#f92572,color:#1b1d1e
style F fill:#f92572,color:#1b1d1e
The key insight: fail before you start, not in the middle.
| Scenario | Apply Fail Fast? | Reasoning |
|---|---|---|
| Invalid user input | Yes | User error, report immediately |
| Missing required config | Yes | Can't continue safely |
| Insufficient permissions | Yes | Operation will fail anyway |
| Resource allocation failure | Yes | Partial allocation is worse |
| Network timeout | No | Use graceful degradation |
| Cache miss | No | Expensive path still works |
Decision rule: Fail fast on precondition failures. Degrade gracefully on runtime failures.
See examples.md for detailed code examples.
See examples.md for detailed code examples.
Comprehensive techniques for implementing fail fast patterns:
Stop execution immediately when errors occur:
set -euo pipefail)Enable strictest validation and error detection:
Validate assumptions and fail if they're wrong:
Determine when to throw vs return, panic vs recover:
Prevent operations from running indefinitely:
See reference.md for additional techniques and detailed examples.
These patterns are complementary, not contradictory:
See examples.md for detailed code examples.
| Error Type | Pattern | Example |
|---|---|---|
| Missing config | Fail Fast | Can't start without database URL |
| Database timeout | Graceful Degradation | Retry, then use cache |
| Invalid input | Fail Fast | Reject malformed request |
| API unavailable | Graceful Degradation | Use backup endpoint |
| Insufficient permissions | Fail Fast | Don't attempt forbidden operation |
| Rate limited | Graceful Degradation | Exponential backoff |
Validating after side effects have occurred.
See examples.md for detailed code examples.
Continuing despite failures.
See examples.md for detailed code examples.
Executing some operations before checking all preconditions.
See examples.md for detailed code examples.
Failing fast but not explaining why.
# Bad: unhelpful error
[ -f "$CONFIG" ] || exit 1
# Good: actionable error message
[ -f "$CONFIG" ] || { echo "Config file not found: $CONFIG. Create it from config.example.yml"; exit 1; }
See examples.md for code examples.
See reference.md for complete documentation.