errors

package
v0.101.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCode

func IsCode(err error, code ErrorCode) bool

IsCode checks if an error is of a specific code.

Types

type AIError

type AIError struct {
	Cause   error
	Context map[string]interface{}
	Code    ErrorCode
	Message string
}

AIError represents a structured error for AI operations.

func AgentExecutionFailed

func AgentExecutionFailed(msg string, cause error) *AIError

AgentExecutionFailed creates an agent execution failed error.

func AgentNotFound

func AgentNotFound(agentType string) *AIError

AgentNotFound creates an agent not found error.

func ContextCanceled

func ContextCanceled(cause error) *AIError

ContextCanceled creates a context canceled error.

func InvalidArgument

func InvalidArgument(msg string) *AIError

InvalidArgument creates an invalid argument error.

func LLMUnavailable

func LLMUnavailable(msg string) *AIError

LLMUnavailable creates an LLM unavailable error.

func RateLimitExceeded

func RateLimitExceeded(msg string) *AIError

RateLimitExceeded creates a rate limit exceeded error.

func ServiceUnavailable

func ServiceUnavailable(msg string) *AIError

ServiceUnavailable creates a service unavailable error.

func Timeout

func Timeout(msg string) *AIError

Timeout creates a timeout error.

func Unauthorized

func Unauthorized(msg string) *AIError

Unauthorized creates an unauthorized error.

func Wrap

func Wrap(cause error, code ErrorCode, msg string) *AIError

Wrap wraps an existing error with additional context.

func (*AIError) Error

func (e *AIError) Error() string

Error implements the error interface.

func (*AIError) GetCode

func (e *AIError) GetCode() ErrorCode

GetCode returns the error code.

func (*AIError) Unwrap

func (e *AIError) Unwrap() error

Unwrap returns the underlying cause.

func (*AIError) WithContext

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

WithContext adds context to the error.

func (*AIError) WithContextMap

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

WithContextMap adds multiple context values to the error.

type ErrorCode

type ErrorCode string

ErrorCode represents a specific error type for AI operations.

const (
	// ErrCodeUnauthorized indicates authentication failure.
	ErrCodeUnauthorized ErrorCode = "UNAUTHORIZED"
	// ErrCodeRateLimitExceeded indicates rate limit has been exceeded.
	ErrCodeRateLimitExceeded ErrorCode = "RATE_LIMIT_EXCEEDED"
	// ErrCodeInvalidArgument indicates invalid input parameters.
	ErrCodeInvalidArgument ErrorCode = "INVALID_ARGUMENT"
	// ErrCodeServiceUnavailable indicates the service is not available.
	ErrCodeServiceUnavailable ErrorCode = "SERVICE_UNAVAILABLE"
	// ErrCodeAgentExecutionFailed indicates agent execution failure.
	ErrCodeAgentExecutionFailed ErrorCode = "AGENT_EXECUTION_FAILED"
	// ErrCodeAgentNotFound indicates the requested agent type does not exist.
	ErrCodeAgentNotFound ErrorCode = "AGENT_NOT_FOUND"
	// ErrCodeLLMUnavailable indicates the LLM service is not available.
	ErrCodeLLMUnavailable ErrorCode = "LLM_UNAVAILABLE"
	// ErrCodeContextCanceled indicates the operation was canceled.
	ErrCodeContextCanceled ErrorCode = "CONTEXT_CANCELED"
	// ErrCodeTimeout indicates the operation timed out.
	ErrCodeTimeout ErrorCode = "TIMEOUT"
)

func GetCodeFromError

func GetCodeFromError(err error, defaultCode ErrorCode) ErrorCode

GetCodeFromError extracts the error code from any error. Returns the provided default code if the error is not an AIError.

Jump to

Keyboard shortcuts

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