/** * 错误处理和分类系统 * 提供统一的错误类型和处理机制 */ /** * 错误分类枚举 */ export declare enum ErrorCategory { /** 网络相关错误 */ NETWORK = "NETWORK", /** 配置相关错误 */ CONFIG = "CONFIG", /** 运行时错误 */ RUNTIME = "RUNTIME", /** 验证错误 */ VALIDATION = "VALIDATION", /** 资源错误 */ RESOURCE = "RESOURCE", /** 协议错误 */ PROTOCOL = "PROTOCOL", /** 适配器错误 */ ADAPTER = "ADAPTER", /** 未知错误 */ UNKNOWN = "UNKNOWN" } /** * 错误严重程度 */ export declare enum ErrorSeverity { /** 低 - 可以忽略或自动恢复 */ LOW = "LOW", /** 中 - 需要记录但可以继续运行 */ MEDIUM = "MEDIUM", /** 高 - 影响功能,需要处理 */ HIGH = "HIGH", /** 严重 - 可能导致服务停止 */ CRITICAL = "CRITICAL" } /** * 基础错误类 */ export declare class OneBotsError extends Error { readonly category: ErrorCategory; readonly severity: ErrorSeverity; readonly code: string; readonly context?: Record; readonly timestamp: Date; readonly cause?: Error; constructor(message: string, options?: { category?: ErrorCategory; severity?: ErrorSeverity; code?: string; context?: Record; cause?: Error; }); /** * 转换为可序列化的对象 */ toJSON(): { name: string; message: string; category: ErrorCategory; severity: ErrorSeverity; code: string; context: Record; timestamp: string; stack: string; cause: { message: string; stack: string; }; }; /** * 转换为字符串 */ toString(): string; } /** * 网络错误 */ export declare class NetworkError extends OneBotsError { constructor(message: string, options?: { context?: Record; cause?: Error; }); } /** * 配置错误 */ export declare class ConfigError extends OneBotsError { constructor(message: string, options?: { context?: Record; cause?: Error; }); } /** * 验证错误 */ export declare class ValidationError extends OneBotsError { constructor(message: string, options?: { context?: Record; cause?: Error; }); } /** * 资源错误 */ export declare class ResourceError extends OneBotsError { constructor(message: string, options?: { context?: Record; cause?: Error; }); } /** * 协议错误 */ export declare class ProtocolError extends OneBotsError { constructor(message: string, options?: { context?: Record; cause?: Error; }); } /** * 适配器错误 */ export declare class AdapterError extends OneBotsError { constructor(message: string, options?: { context?: Record; cause?: Error; code?: string; severity?: ErrorSeverity; }); } export type UnsupportedCapabilityReason = "platform_unsupported" | "not_implemented" | "permission_missing" | "context_missing"; /** * 适配器能力不可用。 * * 调用方可以根据 reason 判断应隐藏功能、提示授权,还是补充会话上下文, * 不再依赖解析各平台自行拼接的错误文本。 */ export declare class UnsupportedCapabilityError extends AdapterError { readonly platform: string; readonly capability: string; readonly reason: UnsupportedCapabilityReason; constructor(options: { platform: string; capability: string; reason?: UnsupportedCapabilityReason; message?: string; context?: Record; }); } /** * 运行时错误 */ export declare class RuntimeError extends OneBotsError { constructor(message: string, options?: { context?: Record; cause?: Error; }); } /** * 错误处理工具函数 */ export declare class ErrorHandler { /** * 包装错误,转换为 OneBotsError */ static wrap(error: unknown, context?: Record): OneBotsError; /** * 判断错误是否可恢复 */ static isRecoverable(error: OneBotsError): boolean; /** * 判断错误是否致命 */ static isFatal(error: OneBotsError): boolean; }