Skip to content
Back to skills

Error Handling

ASecurity

Guides the agent to write robust Python and TypeScript code by applying error handling best practices, timeouts, and graceful shutdown patterns. Trigger this implicitly whenever writing code that interacts with external services, files, or network requests.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 2, 2026
ai-agentstypescriptpythondebuggingrefactoringapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned October 2, 2026

npx -y skills add Gastonchevarria/god-mode --skill error-handling --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Error Handling?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Error Handling
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gastonchevarria-error-handling/badge)](https://www.skillsdirectory.com/skills/gastonchevarria-error-handling)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: error-handling
description: Guides the agent to write robust Python and TypeScript code by applying error handling best practices, timeouts, and graceful shutdown patterns. Trigger this implicitly whenever writing code that interacts with external services, files, or network requests.
---

# Robust Error Handling (Python / TypeScript)

When writing or refactoring code in Python or TypeScript, especially code that deals with I/O, network requests, or long-running processes, you MUST prioritize robustness and apply the following patterns:

## 1. Always Clean Up (try/finally)
Ensure that resources (files, network connections, sessions, clients) are always closed properly.
- **Python**: Use `try/finally` blocks or context managers (`with`).
- **TypeScript**: Use `try/finally` blocks.

## 2. Handle Specific Errors
Do not blindly catch generic exceptions unless it's a top-level fail-safe.
- **Python**: Catch `FileNotFoundError`, `ConnectionError`, `TimeoutError`, etc., before `Exception`.
- **TypeScript**: Check the `error.message` or `error.code` (e.g., `ENOENT`, `ECONNREFUSED`) to handle known failure states gracefully.

## 3. Set Appropriate Timeouts
Never make synchronous or asynchronous calls to external services or long-running processes without setting a timeout.
- Use timeout arguments in APIs when available.
- If not available, use `asyncio.wait_for` (Python) or `Promise.race` with a timeout promise (TypeScript).

## 4. Graceful Shutdown
Long-running scripts should handle interruption signals (e.g., `SIGINT`) to clean up before exiting.
- **Python**: Use the `signal` module to catch `signal.SIGINT` and trigger cleanup tasks.
- **TypeScript**: Use `process.on("SIGINT", ...)` to await cleanup before `process.exit(0)`.

## 5. Log Errors
Always capture and log error details (and stack traces when necessary) for debugging. Don't swallow errors silently.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…