python-error-handling

Replace broad Python exceptions with precise types and boundary strategies.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/jamesogunsan/prod-eng-skills --skill python-error-handling-jamesogunsan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-error-handling
Source: https://github.com/jamesogunsan/prod-eng-skills/tree/main/plugins/python-development/skills/python-error-handling
Command: npx skills add https://github.com/jamesogunsan/prod-eng-skills --skill python-error-handling-jamesogunsan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Improve Python exception handling with guidance on specific exceptions, failure boundaries, recovery strategy, chaining, and safe error reporting. Use for debugging, code reviews, and reliability improvements.

Core Features & Use Cases

  • Clear exception taxonomy and guidance on choosing precise exception types.
  • Strategies for failure boundaries: fail-fast, retry, translation, or fallback.
  • Best practices for preserving context in logs and error messages across layers and boundaries.

Quick Start

Review a sample Python function and apply the guidance to wrap risky calls with narrow exceptions and informative error messages.

Frequently Asked Questions about python-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace broad Python exceptions with precise error types?

Python error handling improves by identifying ambiguous exceptions and replacing them with specific, actionable error types. This ensures failures are caught accurately and handled with appropriate boundary strategies like fail-fast, retry, or fallback.

What is the best way to preserve context when wrapping exceptions in Python?

Preserving context when wrapping exceptions in Python requires retaining the original cause. This prevents losing the root failure trace across boundaries, ensuring logs and error messages remain informative for debugging and reliability improvements.

When should I use fail-fast versus retry strategies for Python exception management?

Fail-fast strategies stop execution immediately upon detecting invalid states, while retry strategies attempt recovery from transient issues. Choose fail-fast for critical failures and retry or fallback for recoverable boundary errors.

How do I prevent sensitive data from leaking in Python error messages?

Preventing sensitive data leaks in Python error messages involves sanitizing logs and avoiding the inclusion of raw user inputs or credentials. Safe error reporting ensures robustness without exposing vulnerabilities during exception translation.

Why does my Python exception handling lose the original traceback across layers?

Losing the original traceback across layers happens when exceptions are caught and raised without chaining. Preserve original causes by using exception chaining in Python, ensuring the full failure context remains visible during debugging.