Receber por email
← Voltar para o catálogo

error-handling-skill

Provides standardized error handling across the application with consistent formatting, logging, and user-friendly messages. Handles an exception by formatting the error message, logging it with context, and returning a…

556estrelas
Atualizado há 2 meses

Ver no GitHub ↗ Licença: MIT

Como adicionar

/plugin marketplace add majiayu000/claude-skill-registry

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Para o autor da skill

Cole no README do seu repo

Mostra que sua skill está catalogada na Skillteca, gera backlink e tráfego rastreável.

[![Skillteca](https://www.skillteca.com.br/api/badge/error-handling-skill/svg)](https://www.skillteca.com.br/skills/error-handling-skill)

Skills relacionadas

Ver todas de Pesquisa e Web →

Alerta por categoria

Receba novas skills de Pesquisa e Web toda segunda

1 email curto, só com as skills novas de Pesquisa e Web. 4 minutos de leitura, sem spam, cancela com 1 clique.

Você confirma o email no primeiro envio. Sem spam. Cancela com 1 clique.

Ler descrição completa

Error Handling Skill

Purpose

Provides standardized error handling across the application with consistent formatting, logging, and user-friendly messages.

Functions

1. handle_error(error: Exception, context: str) -> str

Handles an exception by formatting the error message, logging it with context, and returning a user-friendly message.

Parameters:

  • error (Exception): The exception or error object to handle
  • context (str): Context information about where/why the error occurred

Returns:

  • A user-friendly error message string

Behavior:

  1. Format the error message using format_error_message()
  2. Log the error using log_error()
  3. Return a user-friendly message for display

2. format_error_message(message: str, error_code: str = "") -> str

Formats an error message with consistent styling and optional error code.

Parameters:

  • message (str): The error message to format
  • error_code (str, optional): Error code to include. Defaults to "".

Returns:

  • Formatted error message in the format: "✗ Error: [message]"
  • If error_code is provided: "✗ Error: [message] [error_code]"

Examples:

format_error_message("File not found")  # "✗ Error: File not found"
format_error_message("Connection failed", "ERR_001")  # "✗ Error: Connection failed [ERR_001]"

3. log_error(error: Exception, context: str) -> None

Logs an error to stderr or file with timestamp and context information.

Parameters:

  • error (Exception): The exception or error object to log
  • context (str): Context information about where the error occurred

Returns:

  • None

Log Format:

[TIMESTAMP] ERROR | Context: [context] | Message: [error_message] | Type: [error_type]

Error Message Format

All error messages follow the format:

✗ Error: [message]

Logging Setup

The skill uses Python's standard logging module with the following configuration:

  • Format: [%(asctime)s] %(levelname)s | %(message)s
  • Timestamp: ISO 8601 format
  • Output: stderr by default
  • Can be configured to log to file by setting up a file handler

Usage Example

from error_handling_skill import handle_error, format_error_message, log_error

try:
    risky_operation()
except Exception as e:
    user_message = handle_error(e, "user_authentication")
    print(user_message)
    # Output: "✗ Error: Authentication failed - Invalid credentials"

Implementation Notes

  • All functions include proper type hints
  • All functions have docstrings documenting parameters, returns, and behavior
  • Logging is configurable for different output destinations
  • Error codes are optional but recommended for traceability
Compartilhar X LinkedIn