global-error-handling

在整个应用程序中实现健壮的错误处理,包括用户友好的消息、快速失败验证、特定的异常类型和适当的资源清理。在编写try-catch块、抛出或捕获异常、实现错误边界、处理API错误或管理任何部分的代码库中的错误状态时使用此技能。在早期验证输入(快速失败)、向用户提供清晰可操作的错误消息而不暴露安全细节、使用特定的异常类型而非通用错误、在适当边界实施集中错误处理、设计优雅降级、实现带指数退避的重试逻辑,或确保资源在finally块中被清理时应用此技能。此技能确保错误被适当捕获和处理,即使发生错误用户体验仍然积极,通过不泄露敏感信息维护安全性,系统在非关键服务故障时继续运行或优雅降级。

📖 中文导读:在整个应用程序中实现健壮的错误处理,包括用户友好的消息、快速失败验证、特定的异常类型和适当的资源清理。在编写try-catch块、抛出或捕获异常、实现错误边界、处理API错误或管理任何部分的代码库中的错误状态时使用此技能。在早期验证输入(快速失败)、向用户提供清晰可操作的错误消息而不暴露安全细节、使用特定的异常类型而非通用错误、在适当边界实施集中错误处理、设计优雅降级、实现带指数退避的重试逻辑,或确保资源在finally块中被清理时应用此技能。此技能确保错误被适当捕获和处理,即使发生错误用户体验仍然积极,通过不泄露敏感信息维护安全性,系统在非关键服务故障时继续运行或优雅降级。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: Global Error Handling description: Implement robust error handling with user-friendly messages, fail-fast validation, specific exception types, and proper resource cleanup across the application. Use this skill when writing try-catch blocks, throwing or catching exceptions, implementing error boundaries, handling API errors, or managing error states in any part of the codebase. Apply this skill when validating inputs early (fail fast), providing clear actionable error messages to users without exposing security details, using specific exception types rather than generic errors, implementing centralized error handling at appropriate boundaries, designing for graceful degradation, implementing retry logic with exponential backoff, or ensuring resources are cleaned up in finally blocks. This skill ensures errors are caught and handled appropriately, user experience remains positive even when errors occur, security is maintained by not leaking sensitive information, and systems continue operating or degrade gracefully when non-critical services fail.

Global Error Handling

This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle global error handling.

When to use this skill

  • When writing try-catch-finally blocks or exception handling logic
  • When throwing custom errors or exceptions with meaningful messages
  • When validating inputs and failing fast on invalid data
  • When implementing error boundaries in React or error handling middleware
  • When handling API errors, network failures, or external service calls
  • When providing user-facing error messages that are clear and actionable
  • When logging errors with appropriate context (stack traces, user actions, timestamps)
  • When implementing retry strategies with exponential backoff for transient failures
  • When ensuring resource cleanup (file handles, database connections, network sockets)
  • When centralizing error handling at API controllers, service boundaries, or UI error boundaries
  • When designing systems to degrade gracefully when non-critical services fail
  • When avoiding exposing sensitive information (stack traces, internal paths) to end users
  • When using specific exception types (ValidationError, NotFoundError) instead of generic ones
  • When implementing proper error propagation without swallowing errors silently

Instructions

For details, refer to the information provided in this file: global error handling