errors

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README

errors 错误处理系统

本模块是 goagent 框架的统一错误处理系统,提供结构化、可追踪的错误管理机制。

目录

架构设计

系统架构图
graph TB
    subgraph "错误创建层"
        New[New/Newf<br/>创建新错误]
        Wrap[Wrap/Wrapf<br/>包装现有错误]
        Helpers[专用辅助函数<br/>30+ 个]
    end

    subgraph "错误结构"
        AE[AgentError]
        Code[ErrorCode<br/>错误代码]
        Stack[StackFrame<br/>堆栈跟踪]
        Context[Context<br/>上下文信息]
    end

    subgraph "错误处理层"
        Check[IsCode/IsAgentError<br/>错误检查]
        Extract[GetCode/GetContext<br/>信息提取]
        Chain[ErrorChain/RootCause<br/>错误链分析]
    end

    New --> AE
    Wrap --> AE
    Helpers --> AE
    AE --> Code
    AE --> Stack
    AE --> Context
    AE --> Check
    AE --> Extract
    AE --> Chain

    style AE fill:#e1f5ff
    style Helpers fill:#e8f5e9
错误链模型
graph LR
    E1[AgentError<br/>工具执行错误] --> E2[AgentError<br/>LLM 请求错误]
    E2 --> E3[标准 error<br/>网络超时]

    style E1 fill:#ffcdd2
    style E2 fill:#fff9c4
    style E3 fill:#c8e6c9

错误代码

错误代码分类
分类 错误代码 说明
Agent AGENT_EXECUTION Agent 执行错误
AGENT_VALIDATION Agent 验证错误
AGENT_NOT_FOUND Agent 未找到
AGENT_INITIALIZATION Agent 初始化错误
Tool TOOL_EXECUTION 工具执行错误
TOOL_NOT_FOUND 工具未找到
TOOL_VALIDATION 工具验证错误
TOOL_TIMEOUT 工具超时
TOOL_RETRY_EXHAUSTED 重试次数耗尽
LLM LLM_REQUEST LLM 请求错误
LLM_RESPONSE LLM 响应错误
LLM_TIMEOUT LLM 超时
LLM_RATE_LIMIT LLM 速率限制
Stream STREAM_READ 流读取错误
STREAM_WRITE 流写入错误
STREAM_TIMEOUT 流超时
STREAM_CLOSED 流已关闭
分布式 DISTRIBUTED_CONNECTION 连接错误
DISTRIBUTED_COORDINATION 协调错误
DISTRIBUTED_SERIALIZATION 序列化错误
RAG RETRIEVAL_SEARCH 检索搜索错误
RETRIEVAL_EMBEDDING 嵌入生成错误
DOCUMENT_NOT_FOUND 文档未找到
VECTOR_DIM_MISMATCH 向量维度不匹配
规划 PLANNING_FAILED 规划失败
PLAN_VALIDATION 计划验证错误
PLAN_EXECUTION_FAILED 计划执行失败
通用 INVALID_INPUT 无效输入
INVALID_CONFIG 无效配置
NOT_IMPLEMENTED 未实现
INTERNAL_ERROR 内部错误

核心类型

AgentError 结构
type AgentError struct {
    Code      ErrorCode              // 错误代码
    Message   string                 // 错误信息
    Operation string                 // 操作名称
    Component string                 // 组件名称
    Context   map[string]interface{} // 上下文信息
    Cause     error                  // 底层错误
    Stack     []StackFrame           // 堆栈跟踪
}

type StackFrame struct {
    File     string // 源文件路径
    Line     int    // 行号
    Function string // 函数名
}
方法链构造
err := errors.New(errors.CodeLLMRateLimit, "rate limit exceeded").
    WithComponent("llm_client").
    WithOperation("request").
    WithContext("provider", "openai").
    WithContext("model", "gpt-4").
    WithContext("retry_after_seconds", 60)

使用方法

基础使用
// 方式 1: 直接创建错误
err := errors.New(errors.CodeLLMTimeout, "request timed out after 30 seconds").
    WithComponent("llm").
    WithContext("timeout_seconds", 30)

// 方式 2: 使用专用辅助函数(推荐)
err := errors.NewLLMTimeoutError("openai", "gpt-4", 30)

// 方式 3: 包装现有错误
underlyingErr := fmt.Errorf("network error")
err := errors.Wrap(underlyingErr, errors.CodeLLMRequest, "LLM request failed").
    WithComponent("llm_client").
    WithContext("provider", "openai")
错误检查
// 检查错误代码
if errors.IsCode(err, errors.CodeDocumentNotFound) {
    return 404, "Not Found"
}

if errors.IsCode(err, errors.CodeLLMRateLimit) {
    ctx := errors.GetContext(err)
    retryAfter := ctx["retry_after_seconds"].(int)
    time.Sleep(time.Duration(retryAfter) * time.Second)
}

// 检查是否为 AgentError
if errors.IsAgentError(err) {
    agentErr := err.(*errors.AgentError)
    fmt.Println(agentErr.FormatStack())
}
错误链处理
// 查看完整错误链
chain := errors.ErrorChain(wrappedErr)
for i, e := range chain {
    fmt.Printf("[%d] %v\n", i, e)
}

// 获取根本原因
root := errors.RootCause(wrappedErr)
fmt.Printf("Root cause: %v\n", root)
重试逻辑
for attempt := 1; attempt <= maxAttempts; attempt++ {
    err := doOperation()
    if err == nil {
        return nil
    }

    if errors.IsCode(err, errors.CodeLLMRateLimit) {
        ctx := errors.GetContext(err)
        retryAfter := ctx["retry_after_seconds"].(int)
        time.Sleep(time.Duration(retryAfter) * time.Second)
        continue
    }

    // 不可重试的错误
    return errors.NewToolRetryExhaustedError("operation", attempt, err)
}
HTTP 状态码映射
func errorToHTTPStatus(err error) (int, string) {
    switch errors.GetCode(err) {
    case errors.CodeDocumentNotFound:
        return 404, "Not Found"
    case errors.CodeInvalidInput:
        return 400, "Bad Request"
    case errors.CodeLLMRateLimit:
        return 429, "Too Many Requests"
    case errors.CodeLLMTimeout:
        return 504, "Gateway Timeout"
    default:
        return 500, "Internal Server Error"
    }
}
结构化日志
// 提取错误信息用于日志
logger.Error("operation failed",
    "error_code", errors.GetCode(err),
    "component", errors.GetComponent(err),
    "operation", errors.GetOperation(err),
    "context", errors.GetContext(err),
)

// 打印堆栈跟踪
if agentErr, ok := err.(*errors.AgentError); ok {
    fmt.Println(agentErr.FormatStack())
}

API 参考

构造函数
// 创建新错误
New(code ErrorCode, message string) *AgentError
Newf(code ErrorCode, format string, args ...interface{}) *AgentError

// 包装现有错误
Wrap(err error, code ErrorCode, message string) *AgentError
Wrapf(err error, code ErrorCode, format string, args ...interface{}) *AgentError
流式方法
func (e *AgentError) WithOperation(operation string) *AgentError
func (e *AgentError) WithComponent(component string) *AgentError
func (e *AgentError) WithContext(key string, value interface{}) *AgentError
func (e *AgentError) WithContextMap(ctx map[string]interface{}) *AgentError
检查函数
// 错误代码检查
GetCode(err error) ErrorCode
IsCode(err error, code ErrorCode) bool

// 类型检查
IsAgentError(err error) bool

// 信息提取
GetOperation(err error) string
GetComponent(err error) string
GetContext(err error) map[string]interface{}

// 错误链
ErrorChain(err error) []error
RootCause(err error) error
专用辅助函数
// Agent 相关
NewAgentExecutionError(agentName, operation string, cause error) *AgentError
NewAgentValidationError(agentName, reason string) *AgentError
NewAgentNotFoundError(agentName string) *AgentError
NewAgentInitializationError(agentName string, cause error) *AgentError

// Tool 相关
NewToolExecutionError(toolName, operation string, cause error) *AgentError
NewToolNotFoundError(toolName string) *AgentError
NewToolValidationError(toolName, reason string) *AgentError
NewToolTimeoutError(toolName string, timeoutSeconds int) *AgentError
NewToolRetryExhaustedError(toolName string, attempts int, lastError error) *AgentError

// LLM 相关
NewLLMRequestError(provider, model string, cause error) *AgentError
NewLLMResponseError(provider, model, reason string) *AgentError
NewLLMTimeoutError(provider, model string, timeoutSeconds int) *AgentError
NewLLMRateLimitError(provider, model string, retryAfterSeconds int) *AgentError

// Stream 相关
NewStreamReadError(cause error) *AgentError
NewStreamWriteError(cause error) *AgentError
NewStreamTimeoutError(operation string, timeoutSeconds int) *AgentError
NewStreamClosedError(operation string) *AgentError

// RAG 相关
NewRetrievalSearchError(query string, cause error) *AgentError
NewRetrievalEmbeddingError(text string, cause error) *AgentError
NewDocumentNotFoundError(docID string) *AgentError
NewVectorDimMismatchError(expected, actual int) *AgentError

// Planning 相关
NewPlanningError(goal string, cause error) *AgentError
NewPlanValidationError(planID, reason string) *AgentError
NewPlanExecutionError(planID, stepID string, cause error) *AgentError
NewPlanNotFoundError(planID string) *AgentError

// 通用工具
ErrorWithRetry(err error, attempt, maxAttempts int) *AgentError
ErrorWithDuration(err error, durationMs int64) *AgentError

代码结构

errors/
├── errors.go       # 核心类型和基础方法
│                   # - ErrorCode 常量定义
│                   # - AgentError 结构体
│                   # - 构造函数和流式方法
│                   # - 错误检查和提取函数
│
├── helpers.go      # 30+ 个专用错误创建函数
│                   # - Agent/Tool/LLM/Stream 等
│
└── errors_test.go  # 单元测试

设计特点

结构化错误
  • 错误代码分类:43 种错误类型,覆盖全部业务场景
  • 上下文信息:灵活的 key-value 存储
  • 堆栈跟踪:自动捕获调用栈
错误链支持
  • 实现 Unwrap() 支持 errors.Is()errors.As()
  • 提供 ErrorChain()RootCause() 便捷函数
易于集成
  • 与 Go 标准库 errors 包完全兼容
  • 便于集成到日志、监控、告警系统

扩展阅读

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorChain

func ErrorChain(err error) []error

ErrorChain returns all errors in the error chain

func GetComponent

func GetComponent(err error) string

GetComponent extracts the component from any error

func GetContext

func GetContext(err error) map[string]interface{}

GetContext extracts the context from any error

func GetOperation

func GetOperation(err error) string

GetOperation extracts the operation from any error

func IsAgentError

func IsAgentError(err error) bool

IsAgentError checks if an error is an AgentError

func IsCode

func IsCode(err error, code ErrorCode) bool

IsCode checks if an error has the specified code

func RootCause

func RootCause(err error) error

RootCause returns the root cause of the error chain

Types

type AgentError

type AgentError struct {
	// Code categorizes the error type
	Code ErrorCode

	// Message is the human-readable error message
	Message string

	// Operation identifies what was being attempted
	Operation string

	// Component identifies which component raised the error
	Component string

	// Context provides structured metadata about the error
	Context map[string]interface{}

	// Cause is the underlying error (for error chain)
	Cause error

	// Stack contains the stack trace where the error was created
	Stack []StackFrame
}

AgentError is the structured error type for all agent operations

It provides: - Error codes for categorization - Context preservation through the error chain - Stack trace information for debugging - Structured metadata for logging and monitoring - Operation-specific context

func ErrorWithDuration

func ErrorWithDuration(err error, durationMs int64) *AgentError

ErrorWithDuration wraps an error with duration information

func ErrorWithRetry

func ErrorWithRetry(err error, attempt, maxAttempts int) *AgentError

ErrorWithRetry wraps an error with retry information

func New

func New(code ErrorCode, message string) *AgentError

New creates a new AgentError with the given code and message

func NewAgentExecutionError

func NewAgentExecutionError(agentName, operation string, cause error) *AgentError

NewAgentExecutionError creates an error for agent execution failures

func NewAgentInitializationError

func NewAgentInitializationError(agentName string, cause error) *AgentError

NewAgentInitializationError creates an error for agent initialization failures

func NewAgentNotFoundError

func NewAgentNotFoundError(agentName string) *AgentError

NewAgentNotFoundError creates an error when an agent is not found

func NewAgentValidationError

func NewAgentValidationError(agentName, reason string) *AgentError

NewAgentValidationError creates an error for agent input validation failures

func NewContextCanceledError

func NewContextCanceledError(operation string) *AgentError

NewContextCanceledError creates an error when context is canceled

func NewContextTimeoutError

func NewContextTimeoutError(operation string, timeoutSeconds int) *AgentError

NewContextTimeoutError creates an error when context times out

func NewDistributedConnectionError

func NewDistributedConnectionError(endpoint string, cause error) *AgentError

NewDistributedConnectionError creates an error for distributed connection failures

func NewDistributedCoordinationError

func NewDistributedCoordinationError(operation string, cause error) *AgentError

NewDistributedCoordinationError creates an error for coordination failures

func NewDistributedSerializationError

func NewDistributedSerializationError(dataType string, cause error) *AgentError

NewDistributedSerializationError creates an error for serialization failures

func NewDocumentNotFoundError

func NewDocumentNotFoundError(docID string) *AgentError

NewDocumentNotFoundError creates an error when a document is not found

func NewInternalError

func NewInternalError(component, operation string, cause error) *AgentError

NewInternalError creates an error for internal failures

func NewInvalidConfigError

func NewInvalidConfigError(component, configKey, reason string) *AgentError

NewInvalidConfigError creates an error for invalid configuration

func NewInvalidInputError

func NewInvalidInputError(component, parameter, reason string) *AgentError

NewInvalidInputError creates an error for invalid input

func NewLLMRateLimitError

func NewLLMRateLimitError(provider, model string, retryAfterSeconds int) *AgentError

NewLLMRateLimitError creates an error when LLM rate limit is hit

func NewLLMRequestError

func NewLLMRequestError(provider, model string, cause error) *AgentError

NewLLMRequestError creates an error for LLM request failures

func NewLLMResponseError

func NewLLMResponseError(provider, model, reason string) *AgentError

NewLLMResponseError creates an error for LLM response parsing failures

func NewLLMTimeoutError

func NewLLMTimeoutError(provider, model string, timeoutSeconds int) *AgentError

NewLLMTimeoutError creates an error when LLM request times out

func NewMiddlewareChainError

func NewMiddlewareChainError(position int, cause error) *AgentError

NewMiddlewareChainError creates an error for middleware chain failures

func NewMiddlewareExecutionError

func NewMiddlewareExecutionError(middlewareName, phase string, cause error) *AgentError

NewMiddlewareExecutionError creates an error for middleware execution failures

func NewMiddlewareValidationError

func NewMiddlewareValidationError(middlewareName, reason string) *AgentError

NewMiddlewareValidationError creates an error for middleware validation failures

func NewMultiAgentConsensusError

func NewMultiAgentConsensusError(votes map[string]bool) *AgentError

NewMultiAgentConsensusError creates an error for consensus failures

func NewMultiAgentMessageError

func NewMultiAgentMessageError(topic string, cause error) *AgentError

NewMultiAgentMessageError creates an error for message passing failures

func NewMultiAgentRegistrationError

func NewMultiAgentRegistrationError(agentID string, cause error) *AgentError

NewMultiAgentRegistrationError creates an error for agent registration failures

func NewNotImplementedError

func NewNotImplementedError(component, feature string) *AgentError

NewNotImplementedError creates an error for unimplemented features

func NewParserError

func NewParserError(parserType, content string, cause error) *AgentError

NewParserError creates an error for parser failures

func NewParserInvalidJSONError

func NewParserInvalidJSONError(content string, cause error) *AgentError

NewParserInvalidJSONError creates an error for invalid JSON parsing

func NewParserMissingFieldError

func NewParserMissingFieldError(field string) *AgentError

NewParserMissingFieldError creates an error when a required field is missing

func NewPlanExecutionError

func NewPlanExecutionError(planID, stepID string, cause error) *AgentError

NewPlanExecutionError creates an error for plan execution failures

func NewPlanNotFoundError

func NewPlanNotFoundError(planID string) *AgentError

NewPlanNotFoundError creates an error when a plan is not found

func NewPlanValidationError

func NewPlanValidationError(planID, reason string) *AgentError

NewPlanValidationError creates an error for plan validation failures

func NewPlanningError

func NewPlanningError(goal string, cause error) *AgentError

NewPlanningError creates an error for planning failures

func NewRetrievalEmbeddingError

func NewRetrievalEmbeddingError(text string, cause error) *AgentError

NewRetrievalEmbeddingError creates an error for embedding generation failures

func NewRetrievalSearchError

func NewRetrievalSearchError(query string, cause error) *AgentError

NewRetrievalSearchError creates an error for retrieval search failures

func NewRouterFailedError

func NewRouterFailedError(routerType string, cause error) *AgentError

NewRouterFailedError creates an error for router failures

func NewRouterNoMatchError

func NewRouterNoMatchError(topic, pattern string) *AgentError

NewRouterNoMatchError creates an error when no route matches

func NewRouterOverloadError

func NewRouterOverloadError(capacity, current int) *AgentError

NewRouterOverloadError creates an error when router is overloaded

func NewStateCheckpointError

func NewStateCheckpointError(sessionID string, operation string, cause error) *AgentError

NewStateCheckpointError creates an error for checkpoint operations

func NewStateLoadError

func NewStateLoadError(sessionID string, cause error) *AgentError

NewStateLoadError creates an error for state loading failures

func NewStateSaveError

func NewStateSaveError(sessionID string, cause error) *AgentError

NewStateSaveError creates an error for state saving failures

func NewStateValidationError

func NewStateValidationError(reason string) *AgentError

NewStateValidationError creates an error for state validation failures

func NewStoreConnectionError

func NewStoreConnectionError(storeType, endpoint string, cause error) *AgentError

NewStoreConnectionError creates an error for store connection failures

func NewStoreNotFoundError

func NewStoreNotFoundError(namespace []string, key string) *AgentError

NewStoreNotFoundError creates an error when a store item is not found

func NewStoreSerializationError

func NewStoreSerializationError(key string, cause error) *AgentError

NewStoreSerializationError creates an error for store serialization failures

func NewStreamClosedError

func NewStreamClosedError(operation string) *AgentError

NewStreamClosedError creates an error when operating on a closed stream

func NewStreamReadError

func NewStreamReadError(cause error) *AgentError

NewStreamReadError creates an error for stream reading failures

func NewStreamTimeoutError

func NewStreamTimeoutError(operation string, timeoutSeconds int) *AgentError

NewStreamTimeoutError creates an error when stream operations time out

func NewStreamWriteError

func NewStreamWriteError(cause error) *AgentError

NewStreamWriteError creates an error for stream writing failures

func NewToolExecutionError

func NewToolExecutionError(toolName, operation string, cause error) *AgentError

NewToolExecutionError creates an error for tool execution failures

func NewToolNotFoundError

func NewToolNotFoundError(toolName string) *AgentError

NewToolNotFoundError creates an error when a tool is not found

func NewToolRetryExhaustedError

func NewToolRetryExhaustedError(toolName string, attempts int, lastError error) *AgentError

NewToolRetryExhaustedError creates an error when tool retry attempts are exhausted

func NewToolTimeoutError

func NewToolTimeoutError(toolName string, timeoutSeconds int) *AgentError

NewToolTimeoutError creates an error when a tool execution times out

func NewToolValidationError

func NewToolValidationError(toolName, reason string) *AgentError

NewToolValidationError creates an error for tool input validation failures

func NewVectorDimMismatchError

func NewVectorDimMismatchError(expected, actual int) *AgentError

NewVectorDimMismatchError creates an error for vector dimension mismatches

func Newf

func Newf(code ErrorCode, format string, args ...interface{}) *AgentError

Newf creates a new AgentError with formatted message

func Wrap

func Wrap(err error, code ErrorCode, message string) *AgentError

Wrap wraps an existing error with context

func Wrapf

func Wrapf(err error, code ErrorCode, format string, args ...interface{}) *AgentError

Wrapf wraps an existing error with formatted message

func (*AgentError) Error

func (e *AgentError) Error() string

Error implements the error interface

func (*AgentError) FormatStack

func (e *AgentError) FormatStack() string

FormatStack formats the stack trace for logging

func (*AgentError) Is

func (e *AgentError) Is(target error) bool

Is supports error comparison with errors.Is

func (*AgentError) Unwrap

func (e *AgentError) Unwrap() error

Unwrap returns the underlying cause for error chain support

func (*AgentError) WithComponent

func (e *AgentError) WithComponent(component string) *AgentError

WithComponent sets the component context

func (*AgentError) WithContext

func (e *AgentError) WithContext(key string, value interface{}) *AgentError

WithContext adds a single key-value pair to the context

func (*AgentError) WithContextMap

func (e *AgentError) WithContextMap(ctx map[string]interface{}) *AgentError

WithContextMap adds multiple key-value pairs to the context

func (*AgentError) WithOperation

func (e *AgentError) WithOperation(operation string) *AgentError

WithOperation sets the operation context

type ErrorCode

type ErrorCode string

ErrorCode defines different error categories for agent operations

const (
	// Agent execution errors
	CodeAgentExecution      ErrorCode = "AGENT_EXECUTION"
	CodeAgentValidation     ErrorCode = "AGENT_VALIDATION"
	CodeAgentNotFound       ErrorCode = "AGENT_NOT_FOUND"
	CodeAgentInitialization ErrorCode = "AGENT_INITIALIZATION"

	// Tool errors
	CodeToolExecution      ErrorCode = "TOOL_EXECUTION"
	CodeToolNotFound       ErrorCode = "TOOL_NOT_FOUND"
	CodeToolValidation     ErrorCode = "TOOL_VALIDATION"
	CodeToolTimeout        ErrorCode = "TOOL_TIMEOUT"
	CodeToolRetryExhausted ErrorCode = "TOOL_RETRY_EXHAUSTED"

	// Middleware errors
	CodeMiddlewareExecution  ErrorCode = "MIDDLEWARE_EXECUTION"
	CodeMiddlewareChain      ErrorCode = "MIDDLEWARE_CHAIN"
	CodeMiddlewareValidation ErrorCode = "MIDDLEWARE_VALIDATION"

	// State management errors
	CodeStateLoad       ErrorCode = "STATE_LOAD"
	CodeStateSave       ErrorCode = "STATE_SAVE"
	CodeStateValidation ErrorCode = "STATE_VALIDATION"
	CodeStateCheckpoint ErrorCode = "STATE_CHECKPOINT"

	// Stream processing errors
	CodeStreamRead    ErrorCode = "STREAM_READ"
	CodeStreamWrite   ErrorCode = "STREAM_WRITE"
	CodeStreamTimeout ErrorCode = "STREAM_TIMEOUT"
	CodeStreamClosed  ErrorCode = "STREAM_CLOSED"

	// LLM errors
	CodeLLMRequest   ErrorCode = "LLM_REQUEST"
	CodeLLMResponse  ErrorCode = "LLM_RESPONSE"
	CodeLLMTimeout   ErrorCode = "LLM_TIMEOUT"
	CodeLLMRateLimit ErrorCode = "LLM_RATE_LIMIT"

	// Context errors
	CodeContextCanceled ErrorCode = "CONTEXT_CANCELED"
	CodeContextTimeout  ErrorCode = "CONTEXT_TIMEOUT"

	// General errors
	CodeInvalidInput   ErrorCode = "INVALID_INPUT"
	CodeInvalidConfig  ErrorCode = "INVALID_CONFIG"
	CodeNotImplemented ErrorCode = "NOT_IMPLEMENTED"
	CodeInternal       ErrorCode = "INTERNAL_ERROR"

	// Distributed/Network errors
	CodeDistributedConnection    ErrorCode = "DISTRIBUTED_CONNECTION"
	CodeDistributedSerialization ErrorCode = "DISTRIBUTED_SERIALIZATION"
	CodeDistributedCoordination  ErrorCode = "DISTRIBUTED_COORDINATION"
	CodeDistributedScheduling    ErrorCode = "DISTRIBUTED_SCHEDULING"
	CodeDistributedHeartbeat     ErrorCode = "DISTRIBUTED_HEARTBEAT"
	CodeDistributedRegistry      ErrorCode = "DISTRIBUTED_REGISTRY"

	// Retrieval/RAG errors
	CodeRetrievalSearch    ErrorCode = "RETRIEVAL_SEARCH"
	CodeRetrievalEmbedding ErrorCode = "RETRIEVAL_EMBEDDING"
	CodeDocumentNotFound   ErrorCode = "DOCUMENT_NOT_FOUND"
	CodeVectorDimMismatch  ErrorCode = "VECTOR_DIM_MISMATCH"

	// Planning errors
	CodePlanningFailed      ErrorCode = "PLANNING_FAILED"
	CodePlanValidation      ErrorCode = "PLAN_VALIDATION"
	CodePlanExecutionFailed ErrorCode = "PLAN_EXECUTION_FAILED"
	CodePlanNotFound        ErrorCode = "PLAN_NOT_FOUND"

	// Parser errors
	CodeParserFailed       ErrorCode = "PARSER_FAILED"
	CodeParserInvalidJSON  ErrorCode = "PARSER_INVALID_JSON"
	CodeParserMissingField ErrorCode = "PARSER_MISSING_FIELD"

	// MultiAgent errors
	CodeMultiAgentRegistration ErrorCode = "MULTIAGENT_REGISTRATION"
	CodeMultiAgentConsensus    ErrorCode = "MULTIAGENT_CONSENSUS"
	CodeMultiAgentMessage      ErrorCode = "MULTIAGENT_MESSAGE"

	// Store errors (supplemental)
	CodeStoreConnection    ErrorCode = "STORE_CONNECTION"
	CodeStoreSerialization ErrorCode = "STORE_SERIALIZATION"
	CodeStoreNotFound      ErrorCode = "STORE_NOT_FOUND"

	// Router errors
	CodeRouterNoMatch  ErrorCode = "ROUTER_NO_MATCH"
	CodeRouterFailed   ErrorCode = "ROUTER_FAILED"
	CodeRouterOverload ErrorCode = "ROUTER_OVERLOAD"

	// Plugin/Type system errors
	CodeTypeMismatch  ErrorCode = "TYPE_MISMATCH"
	CodeAlreadyExists ErrorCode = "ALREADY_EXISTS"
	CodeNotFound      ErrorCode = "NOT_FOUND"
	CodeInvalidOutput ErrorCode = "INVALID_OUTPUT"
)

func GetCode

func GetCode(err error) ErrorCode

GetCode extracts the error code from any error

type StackFrame

type StackFrame struct {
	File     string
	Line     int
	Function string
}

StackFrame represents a single frame in a stack trace

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL