python-error-handling

Featured

Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.

AI & Automation 42,652 stars 4509 forks Updated today MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Python Error Handling Build robust Python applications with proper input validation, meaningful exceptions, and graceful failure handling. Good error handling makes debugging easier and systems more reliable. ## When to Use This Skill - Validating user input and API parameters - Designing exception hierarchies for applications - Handling partial failures in batch operations - Converting external data to domain types - Building user-friendly error messages - Implementing fail-fast validation patterns ## Core Concepts ### 1. Fail Fast Validate inputs early, before expensive operations. Report all validation errors at once when possible. ### 2. Meaningful Exceptions Use appropriate exception types with context. Messages should explain what failed, why, and how to fix it. ### 3. Partial Failures In batch operations, don't let one failure abort everything. Track successes and failures separately. ### 4. Preserve Context Chain exceptions to maintain the full error trail for debugging. ## Quick Start ```python def fetch_page(url: str, page_size: int) -> Page: if not url: raise ValueError("'url' is required") if not 1 <= page_size <= 100: raise ValueError(f"'page_size' must be 1-100, got {page_size}") # Now safe to proceed... ``` ## Fundamental Patterns ### Pattern 1: Early Input Validation Validate all inputs at API boundaries before any processing begins. ```python def process_order( order_id: str, quantity: int, discount_...

Details

Author
wshobson
Repository
wshobson/agents
Created
1 years ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category