Agent Skills
› aiming-lab/MetaClaw
› robust-error-handling-in-scripts
robust-error-handling-in-scripts
GitHub提供Shell和Python脚本的健壮错误处理最佳实践,包括立即退出、日志记录及指数退避重试机制,防止静默失败。
Trigger Scenarios
编写自动化脚本
开发批处理作业
需要增强脚本容错性
Install
npx skills add aiming-lab/MetaClaw --skill robust-error-handling-in-scripts -g -y
SKILL.md
Frontmatter
{
"name": "robust-error-handling-in-scripts",
"category": "automation",
"description": "Use this skill when writing shell scripts, Python automation, or any unattended batch job. Ensure failures are detected, logged, and handled — never silently ignored."
}
Robust Error Handling in Scripts
Shell scripts:
set -euo pipefail # Exit on error, undefined var, pipe failure
trap 'echo "Failed at line $LINENO"' ERR
Python scripts:
import logging, sys
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
try:
main()
except Exception as e:
logging.exception("Unhandled error: %s", e)
sys.exit(1)
Retry with backoff for transient network/API failures:
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(stop=stop_after_attempt(3), wait=wait_exponential(min=2, max=10))
def call_api(): ...
Version History
- 922caf3 Current 2026-07-25 11:08


