Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

dotnet-exception-handling

БесплатноБез исполняемых скриптовНе проверен

Comprehensive .NET exception handling quality improvement workflow. Auto-detects .NET projects, investigates 10 common exception handling mistakes, generates…

rysweetот rysweet★ 77 звёзд на GitHub

Об этом скилле

.NET Exception Handling Quality Improvement

Purpose

Systematic investigation and remediation of .NET exception handling anti-patterns. Detects, documents, and fixes the 10 most common exception handling mistakes in .NET applications.

Use when: Preparing for production, code quality audits, security reviews, or onboarding to a .NET codebase.

Usage

# Investigation only (default)
/dotnet-exception-handling <path-to-dotnet-project>

# Filter by severity
/dotnet-exception-handling <project-path> --priority critical

# Auto-implement all fixes
/dotnet-exception-handling <project-path> --fix-all

Arguments:

  • project-path: Directory containing .csproj or .sln (default: current directory)
  • --priority: critical | high | medium | low | all (default: all)
  • --fix-all: Implement fixes automatically (default: investigate only)

The 10 Common Mistakes

  1. Catching Exception Too Broadly - Base Exception instead of specific types
  2. Swallowing Exceptions Silently - Empty catch blocks hiding errors
  3. Using throw ex; - Resets stack traces (use throw;)
  4. Wrapping Everything in Try/Catch - Defensive coding clutter
  5. Exceptions for Control Flow - Performance overhead for expected conditions
  6. Forgetting to Await Async - Unhandled exceptions on background threads
  7. Ignoring Background Task Exceptions - Fire-and-forget losing errors
  8. Generic Exception Types - Vague new Exception() instead of specific types
  9. Losing Inner Exceptions - Breaking exception chains
  10. Missing Global Handler - No centralized error handling (stack traces exposed)

Detailed descriptions, detection patterns, and fix templates → see reference.md

Execution Workflow

Phase 1: Investigation (6 Steps)

Step 1: Project Detection

  • Scan for .csproj, .sln files
  • Identify project types (ASP.NET Core, worker services, libraries)
  • Count C# files for scope estimation

Step 2: Parallel Analysis

  • Deploy 5 specialized agents:
    • Background Worker Specialist
    • API Layer Specialist
    • Service Layer Specialist
    • Data Layer Specialist
    • Infrastructure Specialist

Step 3: Violation Detection

  • Use rg -P (ripgrep PCRE mode) for pattern matching:

    # Mistake #1: Broad catches
    rg -P 'catch\s*\(Exception\b' --glob '*.cs'
    
    # Mistake #2: Empty catches
    rg -P 'catch[^{]*\{\s*(//[^\n]*)?\s*\}' --glob '*.cs'
    
    # Mistake #3: throw ex
    rg 'throw\s+ex;' --glob '*.cs'
    
  • See reference.md for complete pattern list

Step 4: Severity Classification

  • CRITICAL: Security (stack trace exposure, missing global handler)
  • HIGH: Reliability (swallowed exceptions, broad catches)
  • MEDIUM: Code quality (excessive try/catch)
  • LOW: Style issues

Step 5: Findings Report

  • Generate markdown with file:line references
  • Code snippets + recommended fixes
  • Priority-based roadmap

Step 6: Knowledge Capture

  • Store in .claude/runtime/logs/EXCEPTION_INVESTIGATION_YYYY-MM-DD.md
  • Update project memory

Phase 2: Development (If --fix-all)

Step 7: Orchestrate Default Workflow

  • Create GitHub issue with findings
  • Set up worktree for fixes
  • Implement GlobalExceptionHandler, Result, etc.
  • Write comprehensive tests (TDD)
  • Three-agent review (reviewer, security, philosophy)

Step 8: Validation

  • All tests pass
  • Security: Zero stack traces
  • Performance: <5ms p99 overhead

Quick Start Examples

Example 1: Investigation Only

/dotnet-exception-handling ./src/MyApi

Output: Investigation report with 23 violations (1 CRITICAL, 8 HIGH, 12 MEDIUM, 2 LOW)

Example 2: Fix Critical Only

/dotnet-exception-handling ./src/MyApi --priority critical --fix-all

Output: GitHub issue + PR implementing GlobalExceptionHandler + 15 tests

Example 3: Complete Fix

/dotnet-exception-handling ./src/MyApi --fix-all

Output: 23 violations fixed, 67 tests, PR ready (CI passing)

Core Architecture Patterns

GlobalExceptionHandler (IExceptionHandler)

Centralized exception-to-HTTP mapping for ASP.NET Core:

public class GlobalExceptionHandler : IExceptionHandler
{
    public async ValueTask<bool> TryHandleAsync(
        HttpContext httpContext,
        Exception exception,
        CancellationToken cancellationToken)
    {
        var (statusCode, title) = exception switch
        {
            ArgumentException => (400, "Invalid request"),
            NotFoundException => (404, "Not found"),
            ConflictException => (409, "Conflict"),
            _ => (500, "Internal server error")
        };

        httpContext.Response.StatusCode = statusCode;
        await httpContext.Response.WriteAsJsonAsync(new ProblemDetails
        {
            Status = statusCode,
            Title = title,
            Detail = statusCode >= 500
                ? "An error occurred"
                : exception.Message
        }, cancellationToke
Полный SKILL.md на GitHub

Установить dotnet-exception-handling в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

examples.mdpatterns.mdreference.md

FAQ

Что делает скилл dotnet-exception-handling?

Comprehensive .NET exception handling quality improvement workflow. Auto-detects .NET projects, investigates 10 common exception handling mistakes, generates prioritized findings, and orchestrates fixes following best practices.

Как установить скилл dotnet-exception-handling?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл dotnet-exception-handling запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить dotnet-exception-handling с