Documentation
¶
Index ¶
- func GetMessage(err error) string
- func GetUserMessage(err error) string
- func Is(err error, code ErrorCode) bool
- func IsFatal(err error) bool
- func IsRetryable(err error) bool
- type AppError
- func AlreadyExists(what string) *AppError
- func InvalidConfig(msg string) *AppError
- func InvalidInput(msg string) *AppError
- func MemoryOperationFailed(op string, err error) *AppError
- func New(code ErrorCode, message string) *AppError
- func NotFound(what string) *AppError
- func ProviderUnavailable(provider string) *AppError
- func SessionNotFound(id string) *AppError
- func SkillNotFound(name string) *AppError
- func Timeout(operation string) *AppError
- func ToolExecutionFailed(name string, err error) *AppError
- func ToolNotFound(name string) *AppError
- func Wrap(err error, code ErrorCode, message string) *AppError
- func Wrapf(err error, code ErrorCode, format string, args ...any) *AppError
- type ErrorClassifier
- type ErrorCode
- type ErrorHandler
- func (h *ErrorHandler) Handle(err error)
- func (h *ErrorHandler) HandleWithFields(err error, fields ...zap.Field)
- func (h *ErrorHandler) Handlef(err error, format string, args ...any)
- func (h *ErrorHandler) Recover(operation string) error
- func (h *ErrorHandler) Validate(err error, code ErrorCode, message string) error
- type FailoverReason
- type SimpleErrorClassifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetUserMessage ¶
GetUserMessage returns a user-friendly error message
Types ¶
type AppError ¶
type AppError struct {
Code ErrorCode
Message string
Err error
StackTrace string
Context map[string]any
}
AppError represents a structured application error
func AlreadyExists ¶
func InvalidConfig ¶
func MemoryOperationFailed ¶
func ProviderUnavailable ¶
func SessionNotFound ¶
func SkillNotFound ¶
func ToolExecutionFailed ¶
func ToolNotFound ¶
type ErrorClassifier ¶
type ErrorClassifier interface {
ClassifyError(err error) FailoverReason
IsFailoverError(err error) bool
}
ErrorClassifier 错误分类器接口
type ErrorCode ¶
type ErrorCode string
ErrorCode represents a unique error code
const ( // General errors ErrCodeUnknown ErrorCode = "UNKNOWN" ErrCodeInvalidInput ErrorCode = "INVALID_INPUT" ErrCodeInvalidConfig ErrorCode = "INVALID_CONFIG" ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeAlreadyExists ErrorCode = "ALREADY_EXISTS" ErrCodePermission ErrorCode = "PERMISSION_DENIED" ErrCodeTimeout ErrorCode = "TIMEOUT" ErrCodeRateLimit ErrorCode = "RATE_LIMIT" ErrCodeAuth ErrorCode = "AUTHENTICATION_FAILED" ErrCodeBilling ErrorCode = "BILLING_ERROR" ErrCodeContextOverflow ErrorCode = "CONTEXT_OVERFLOW" // Agent errors ErrCodeAgentNotRunning ErrorCode = "AGENT_NOT_RUNNING" ErrCodeAgentStartFailed ErrorCode = "AGENT_START_FAILED" ErrCodeAgentStopFailed ErrorCode = "AGENT_STOP_FAILED" ErrCodeToolExecution ErrorCode = "TOOL_EXECUTION_FAILED" ErrCodeToolNotFound ErrorCode = "TOOL_NOT_FOUND" ErrCodeSkillNotFound ErrorCode = "SKILL_NOT_FOUND" ErrCodeSkillLoadFailed ErrorCode = "SKILL_LOAD_FAILED" // Provider errors ErrCodeProviderTimeout ErrorCode = "PROVIDER_TIMEOUT" ErrCodeProviderError ErrorCode = "PROVIDER_ERROR" ErrCodeProviderResponse ErrorCode = "PROVIDER_RESPONSE_ERROR" // Channel errors ErrCodeChannelNotConfigured ErrorCode = "CHANNEL_NOT_CONFIGURED" ErrCodeChannelSendFailed ErrorCode = "CHANNEL_SEND_FAILED" ErrCodeChannelReceive ErrorCode = "CHANNEL_RECEIVE_ERROR" // Memory errors ErrCodeMemoryNotFound ErrorCode = "MEMORY_NOT_FOUND" ErrCodeMemorySaveFailed ErrorCode = "MEMORY_SAVE_FAILED" ErrCodeMemoryLoadFailed ErrorCode = "MEMORY_LOAD_FAILED" ErrCodeMemorySearchFailed ErrorCode = "MEMORY_SEARCH_FAILED" // Session errors ErrCodeSessionNotFound ErrorCode = "SESSION_NOT_FOUND" ErrCodeSessionCreate ErrorCode = "SESSION_CREATE_FAILED" ErrCodeSessionSave ErrorCode = "SESSION_SAVE_FAILED" ErrCodeSessionCorrupted ErrorCode = "SESSION_CORRUPTED" )
type ErrorHandler ¶
type ErrorHandler struct {
// contains filtered or unexported fields
}
ErrorHandler provides centralized error handling
func NewErrorHandler ¶
func NewErrorHandler() *ErrorHandler
NewErrorHandler creates a new error handler
func (*ErrorHandler) Handle ¶
func (h *ErrorHandler) Handle(err error)
Handle handles an error with appropriate logging based on severity
func (*ErrorHandler) HandleWithFields ¶
func (h *ErrorHandler) HandleWithFields(err error, fields ...zap.Field)
HandleWithFields handles an error with additional fields
func (*ErrorHandler) Handlef ¶
func (h *ErrorHandler) Handlef(err error, format string, args ...any)
Handlef handles an error with formatted message
func (*ErrorHandler) Recover ¶
func (h *ErrorHandler) Recover(operation string) error
Recover handles panics and converts to errors
type FailoverReason ¶
type FailoverReason string
FailoverReason 失败原因类型
const ( // FailoverReasonAuth 认证错误 FailoverReasonAuth FailoverReason = "auth" // FailoverReasonRateLimit 速率限制 FailoverReasonRateLimit FailoverReason = "rate_limit" // FailoverReasonTimeout 超时 FailoverReasonTimeout FailoverReason = "timeout" // FailoverReasonBilling 计费错误 FailoverReasonBilling FailoverReason = "billing" // FailoverReasonContextOverflow 上下文溢出 FailoverReasonContextOverflow FailoverReason = "context_overflow" // FailoverReasonUnknown 未知错误 FailoverReasonUnknown FailoverReason = "unknown" )
type SimpleErrorClassifier ¶
type SimpleErrorClassifier struct {
// contains filtered or unexported fields
}
SimpleErrorClassifier 简单的错误分类器实现
func NewSimpleErrorClassifier ¶
func NewSimpleErrorClassifier() *SimpleErrorClassifier
NewSimpleErrorClassifier 创建简单错误分类器
func (*SimpleErrorClassifier) ClassifyError ¶
func (c *SimpleErrorClassifier) ClassifyError(err error) FailoverReason
ClassifyError 分类错误
func (*SimpleErrorClassifier) IsFailoverError ¶
func (c *SimpleErrorClassifier) IsFailoverError(err error) bool
IsFailoverError 检查是否为可回退的错误
Click to show internal directories.
Click to hide internal directories.