Agent skill
Error Handling Strategies
Implement robust error handling with proper validation, recovery mechanisms, and clear feedback for system stability
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/product/error-handling-strategies
SKILL.md
Error Handling Strategies
Purpose
Implement robust error handling that gracefully manages failures, provides clear feedback, and maintains system stability.
When to Use
- Writing any code that can fail
- Handling external API calls
- Processing user input
- Managing file I/O operations
- Dealing with network requests
Key Capabilities
- Error Detection - Identify potential failure points
- Error Recovery - Implement fallback strategies
- Error Communication - Provide clear, actionable messages
Approach
- Identify what can go wrong (invalid input, network failure, etc.)
- Validate inputs before processing
- Use try-catch or error returns appropriately
- Provide context in error messages
- Log errors with sufficient debugging information
- Implement retry logic for transient failures
Example
Context: File reading operation
def read_config(filepath):
try:
with open(filepath, 'r') as f:
return json.load(f)
except FileNotFoundError:
logger.error(f"Config file not found: {filepath}")
return get_default_config()
except json.JSONDecodeError as e:
logger.error(f"Invalid JSON in {filepath}: {e}")
raise ConfigurationError(f"Config file is malformed at line {e.lineno}")
except PermissionError:
logger.error(f"Cannot read {filepath}: Permission denied")
raise ConfigurationError(f"Insufficient permissions for {filepath}")
Best Practices
- ✅ Fail fast for programming errors
- ✅ Recover gracefully from external failures
- ✅ Include context in error messages
- ❌ Avoid: Silent failures or generic error messages
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?