errors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides error types for amq

Index

Constants

This section is empty.

Variables

View Source
var (
	// Queue errors
	ErrQueueNotFound = errors.New("queue not found")
	ErrQueueExists   = errors.New("queue already exists")
	ErrQueueFull     = errors.New("queue at capacity")
	ErrQueueEmpty    = errors.New("queue is empty")

	// Client errors
	ErrClientNotFound  = errors.New("client not registered")
	ErrClientExists    = errors.New("client already exists")
	ErrClientNotActive = errors.New("client not active")

	// Message errors
	ErrMessageNotFound = errors.New("message not found")
	ErrMessageExpired  = errors.New("message TTL exceeded")
	ErrMessageTooLarge = errors.New("message exceeds size limit")
	ErrInvalidMessage  = errors.New("invalid message format")

	// Subscription errors
	ErrNotSubscribed     = errors.New("client not subscribed to topic")
	ErrAlreadySubscribed = errors.New("client already subscribed")

	// System errors
	ErrBackpressure = errors.New("system under load")
	ErrCircuitOpen  = errors.New("circuit breaker open")
	ErrShuttingDown = errors.New("system shutting down")
	ErrTimeout      = errors.New("operation timed out")

	// Storage errors
	ErrStorageFailure    = errors.New("storage operation failed")
	ErrTransactionFailed = errors.New("transaction failed")
)

Common AMQ errors

Functions

func IsFatal

func IsFatal(err error) bool

IsFatal returns true if the error is fatal and should not be retried

func IsRetryable

func IsRetryable(err error) bool

IsRetryable returns true if the error is retryable

Types

type AMQError

type AMQError struct {
	Code      ErrorCode   `json:"code"`
	Message   string      `json:"message"`
	Component string      `json:"component"`
	Timestamp time.Time   `json:"timestamp"`
	Cause     error       `json:"-"`
	Details   interface{} `json:"details,omitempty"`
}

AMQError provides structured error information

func NewAMQError

func NewAMQError(code ErrorCode, component, message string) *AMQError

NewAMQError creates a new AMQ error

func (*AMQError) Error

func (e *AMQError) Error() string

Error implements the error interface

func (*AMQError) Unwrap

func (e *AMQError) Unwrap() error

Unwrap returns the underlying error

func (*AMQError) WithCause

func (e *AMQError) WithCause(cause error) *AMQError

WithCause adds a cause to the error

func (*AMQError) WithDetails

func (e *AMQError) WithDetails(details interface{}) *AMQError

WithDetails adds details to the error

type APIError

type APIError struct {
	Code       int    `json:"code"`
	Message    string `json:"message"`
	StatusCode int    `json:"status_code"`
}

APIError represents an API error

func NewAPIError

func NewAPIError(statusCode int, message string) *APIError

NewAPIError creates a new API error

func (*APIError) Error

func (e *APIError) Error() string

type ErrorCode

type ErrorCode int

ErrorCode represents specific error codes

const (
	// Queue errors (1000-1999)
	CodeQueueNotFound ErrorCode = 1001
	CodeQueueExists   ErrorCode = 1002
	CodeQueueFull     ErrorCode = 1003
	CodeQueueEmpty    ErrorCode = 1004

	// Client errors (2000-2999)
	CodeClientNotFound  ErrorCode = 2001
	CodeClientExists    ErrorCode = 2002
	CodeClientNotActive ErrorCode = 2003
	CodeAuthFailed      ErrorCode = 2004

	// Message errors (3000-3999)
	CodeMessageNotFound ErrorCode = 3001
	CodeMessageExpired  ErrorCode = 3002
	CodeMessageTooLarge ErrorCode = 3003
	CodeInvalidMessage  ErrorCode = 3004

	// System errors (4000-4999)
	CodeBackpressure ErrorCode = 4001
	CodeCircuitOpen  ErrorCode = 4002
	CodeShuttingDown ErrorCode = 4003
	CodeTimeout      ErrorCode = 4004
	CodeRateLimited  ErrorCode = 4005

	// Storage errors (5000-5999)
	CodeStorageFailure    ErrorCode = 5001
	CodeTransactionFailed ErrorCode = 5002
)

type ErrorResponse

type ErrorResponse struct {
	Error     string      `json:"error"`
	Code      ErrorCode   `json:"code"`
	Timestamp time.Time   `json:"timestamp"`
	RequestID string      `json:"request_id,omitempty"`
	Details   interface{} `json:"details,omitempty"`
}

ErrorResponse is used for API error responses

func NewErrorResponse

func NewErrorResponse(err error, requestID string) *ErrorResponse

NewErrorResponse creates a new error response

Jump to

Keyboard shortcuts

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