Token导航 LogoToken导航TokenDH.com
研究检索可写文件github未标认证来源可访问clear审计未展示

error-handling错误处理

Agent Skill

error-handling 用于记录任务执行中的错误、用户纠正、经验和能力缺口,适合在 Codex、Claude、Cursor、Gemini CLI 中希望让 Agent 持续沉淀问题、修正和最佳实践时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

312

周安装

13

GitHub Stars

公开资料未说明

下载量

104
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:error-handling(错误处理)
来源仓库:https://github.com/yosrbennagra/3sc
仓库路径:skills/error-handling
安装命令:
npx skills add yosrbennagra/3sc --skill "error-handling"
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

AgentSkills.tonpx skills
npx skills add yosrbennagra/3sc --skill "error-handling"

简介

error-handling 用于记录任务执行中的错误、用户纠正、经验和能力缺口,适合让 Agent 持续沉淀问题、修正和最佳实践。

  • 适用于错误处理相关的经验积累和最佳实践沉淀,可结合来源仓库和原始 README 继续核验具体用法。
  • 通过 npx skills add yosrbennagra/3sc --skill "error-handling" 命令安装。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

name
error-handling
description
Global error handling for the 3SC widget host. Covers exception handling, crash reporting, user-friendly error surfaces, and recovery strategies.

Error Handling

Overview

Provide consistent, user-safe error handling across the shell, widgets, and background services. Users should never see stack traces or cryptic error messages.

Definition of Done (DoD)

  • [ ] Global handlers registered in App.xaml.cs for all exception sources
  • [ ] All exceptions logged with correlation IDs and context
  • [ ] User sees friendly, actionable error messages
  • [ ] Crash reports saved locally with sanitized data
  • [ ] No swallowed exceptions without explicit justification
  • [ ] Widget errors don't crash the host application

Global Exception Handlers

App.xaml.cs Registration

private void RegisterGlobalExceptionHandlers()
{
    // UI thread exceptions
    DispatcherUnhandledException += OnDispatcherUnhandledException;
    
    // Background thread exceptions
    AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
    
    // Task exceptions that aren't observed
    TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
}

private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
    var correlationId = CorrelationContext.Current ?? Guid.NewGuid().ToString("N")[..8];
    
    Log.Error(e.Exception, 
        "Unhandled UI exception. CorrelationId: {CorrelationId}", correlationId);
    
    // Save crash report
    CrashReportService.SaveReport(e.Exception, correlationId);
    
    // Show user-friendly message
    ShowErrorToUser(e.Exception, correlationId);
    
    // Prevent app crash for recoverable errors
    e.Handled = IsRecoverableError(e.Exception);
}

private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    var exception = e.ExceptionObject as Exception;
    var correlationId = Guid.NewGuid().ToString("N")[..8];
    
    Log.Fatal(exception, 
        "Fatal unhandled exception. Terminating: {IsTerminating}, CorrelationId: {CorrelationId}", 
        e.IsTerminating, correlationId);
    
    CrashReportService.SaveReport(exception, correlationId);
}

private void OnUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{
    Log.Error(e.Exception, "Unobserved task exception");
    
    // Prevent app crash - log and continue
    e.SetObserved();
}

Recoverable vs Fatal Errors

private static bool IsRecoverableError(Exception ex) => ex switch
{
    // Network issues - recoverable
    HttpRequestException => true,
    TaskCanceledException => true,
    
    // Database issues - might recover
    DbUpdateException => true,
    
    // Widget errors - definitely recoverable (isolate the widget)
    WidgetLoadException => true,
    WidgetExecutionException => true,
    
    // Memory/system issues - not recoverable
    OutOfMemoryException => false,
    StackOverflowException => false,
    AccessViolationException => false,
    
    _ => true  // Default to recoverable
};

ViewModel Error Handling

Async Command Pattern

[RelayCommand]
private async Task LoadWidgetsAsync(CancellationToken ct)
{
    IsLoading = true;
    ErrorMessage = null;
    
    try
    {
        var widgets = await _repository.GetAllAsync(ct);
        Widgets = new ObservableCollection<WidgetViewModel>(
            widgets.Select(w => new WidgetViewModel(w)));
    }
    catch (OperationCanceledException)
    {
        // User cancelled - not an error
        Log.Debug("Widget loading cancelled by user");
    }
    catch (Exception ex)
    {
        Log.Error(ex, "Failed to load widgets");
        ErrorMessage = "Failed to load widgets. Please try again.";
        
        // Optionally show toast/notification
        _notifications.ShowError("Could not load widgets");
    }
    finally
    {
        IsLoading = false;
    }
}

Error Display Patterns

public partial class WidgetLibraryViewModel : ObservableObject
{
    [ObservableProperty]
    private string? _errorMessage;
    
    [ObservableProperty]
    private ErrorSeverity _errorSeverity = ErrorSeverity.None;
    
    public bool HasError => !string.IsNullOrEmpty(ErrorMessage);
    
    private void SetError(string message, ErrorSeverity severity = ErrorSeverity.Error)
    {
        ErrorMessage = message;
        ErrorSeverity = severity;
        OnPropertyChanged(nameof(HasError));
    }
    
    private void ClearError()
    {
        ErrorMessage = null;
        ErrorSeverity = ErrorSeverity.None;
        OnPropertyChanged(nameof(HasError));
    }
}

public enum ErrorSeverity { None, Info, Warning, Error }

User Error Messages

Safe Message Mapping

public static class UserMessages
{
    public static string FromException(Exception ex) => ex switch
    {
        HttpRequestException => 
            "Unable to connect to the server. Please check your internet connection.",
        
        DbUpdateException => 
            "Failed to save changes. Please try again.",
        
        FileNotFoundException => 
            "The requested file could not be found.",
        
        UnauthorizedAccessException => 
            "Access denied. You may need to run as administrator.",
        
        WidgetLoadException wle => 
            $"Widget '{wle.WidgetKey}' failed to load. It may be corrupted or incompatible.",
        
        TimeoutException => 
            "The operation timed out. Please try again.",
        
        _ => "An unexpected error occurred. Please try again."
    };
    
    public static string WithCorrelationId(string message, string correlationId) =>
        $"{message}\n\nReference: {correlationId}";
}

Widget Error Isolation

public async Task<bool> SafeLoadWidgetAsync(string widgetKey)
{
    try
    {
        var widget = await _loader.LoadWidgetAsync(widgetKey);
        await widget.InitializeAsync();
        return true;
    }
    catch (Exception ex)
    {
        Log.Error(ex, "Widget {WidgetKey} failed to load", widgetKey);
        
        // Mark widget as problematic
        await _widgetRepo.MarkAsFailedAsync(widgetKey, ex.Message);
        
        // Notify user but don't crash
        _notifications.ShowError($"Widget '{widgetKey}' failed to load");
        
        return false;
    }
}

// Widget execution wrapper
public void SafeExecuteWidgetAction(string widgetKey, Action action)
{
    try
    {
        action();
    }
    catch (Exception ex)
    {
        Log.Error(ex, "Widget {WidgetKey} action failed", widgetKey);
        
        // Optionally disable the widget
        if (ShouldDisableWidget(ex))
        {
            DisableWidget(widgetKey, "Repeated failures");
        }
    }
}

Crash Reports

Crash Report Service

public static class CrashReportService
{
    private static readonly string CrashFolder = Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
        "3SC", "crashes");
    
    public static void SaveReport(Exception? exception, string correlationId)
    {
        try
        {
            Directory.CreateDirectory(CrashFolder);
            
            var report = new CrashReport
            {
                Timestamp = DateTimeOffset.UtcNow,
                CorrelationId = correlationId,
                AppVersion = GetAppVersion(),
                OsVersion = Environment.OSVersion.ToString(),
                ExceptionType = exception?.GetType().FullName,
                Message = exception?.Message,
                StackTrace = SanitizeStackTrace(exception?.ToString()),
                AdditionalContext = GatherContext()
            };
            
            var fileName = $"crash_{DateTime.UtcNow:yyyyMMdd_HHmmss}_{correlationId}.json";
            var filePath = Path.Combine(CrashFolder, fileName);
            
            File.WriteAllText(filePath, JsonSerializer.Serialize(report, new JsonSerializerOptions
            {
                WriteIndented = true
            }));
            
            // Cleanup old reports (keep last 50)
            CleanupOldReports(maxReports: 50);
        }
        catch
        {
            // Never throw from crash reporting
        }
    }
    
    private static string? SanitizeStackTrace(string? stackTrace)
    {
        if (string.IsNullOrEmpty(stackTrace)) return null;
        
        var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        return stackTrace.Replace(userProfile, "[USER]");
    }
}

Error UI Components

Error Banner (XAML)

<Border x:Name="ErrorBanner"
        Visibility="{Binding HasError, Converter={StaticResource BoolToVisibility}}"
        Background="{DynamicResource ErrorBackgroundBrush}"
        Padding="12,8">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        
        <Path Data="{StaticResource ErrorIcon}" 
              Fill="{DynamicResource ErrorForegroundBrush}" />
        
        <TextBlock Grid.Column="1" 
                   Text="{Binding ErrorMessage}"
                   Foreground="{DynamicResource ErrorForegroundBrush}"
                   Margin="8,0" />
        
        <Button Grid.Column="2" 
                Command="{Binding DismissErrorCommand}"
                Content="✕"
                Style="{StaticResource IconButton}" />
    </Grid>
</Border>

Best Practices

PracticeReason
Log before showing user messageCapture full context for debugging
Include correlation IDEnables support to find logs
Sanitize sensitive dataProtect user privacy in reports
Isolate widget errorsDon't let plugins crash the host
Use structured exception typesEasier to handle specifically
Provide actionable messagesHelp users resolve issues

Anti-Patterns

Anti-PatternProblemSolution
catch { }Swallows all errors silentlyAt minimum log the exception
Showing stack tracesConfuses users, security riskMap to friendly messages
Throwing from exception handlersRecursive failureAlways catch in handlers
Generic error messages onlyUser can't act on themBe specific when possible

References

  • references/global-handlers.md for exception hooks
  • references/ui-errors.md for UI surface patterns
  • references/crash-reporting.md for report capture and storage

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Gemini CLI

30.29%
按下载量换算32

windsurf

23.61%
按下载量换算25

trae

17.95%
按下载量换算19

OpenCode

11.95%
按下载量换算12

Codex

7.92%
按下载量换算8

Claude Code

4%
按下载量换算4

安全审计

暂无安全审计结果可展示。

权限和风险

可写文件

该 Skill 可能写入或修改本地文件,使用前需要确认目标目录和修改范围。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills