fail-early-pattern

Installation
SKILL.md

Fail Early

If something is going to fail, it should fail as early as possible, as loudly as possible, with as much context as possible. This skill codifies the fail-early pattern: validating inputs at system boundaries, using guard clauses to reject bad state before it propagates, and writing error messages that answer what failed, where, why, and how to fix it.

When to Use

  • Writing or reviewing functions that accept external input (user data, API responses, file contents)
  • Adding input validation to package functions before CRAN submission
  • Refactoring code that silently produces wrong results instead of erroring
  • Reviewing pull requests for error-handling quality
  • Hardening internal APIs against invalid arguments

Inputs

  • Required: Function or module to apply the pattern to
  • Required: Identification of trust boundaries (where external data enters)
  • Optional: Existing error-handling code to refactor
  • Optional: Target language (default: R; also applies to Python, TypeScript, Rust)
Related skills
Installs
1
GitHub Stars
13
First Seen
Mar 18, 2026