errors

package
v0.1.3 Latest Latest
Warning

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

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

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