Documentation
¶
Overview ¶
Package errors provides structured error handling for Typosentinel This package implements comprehensive error types with context and categorization
Index ¶
- func GetHTTPStatus(err error) int
- func HasCode(err error, code ErrorCode) bool
- func IsAppError(err error) bool
- func IsRetryable(err error) bool
- type AppError
- func GetAppError(err error) *AppError
- func New(code ErrorCode, message string) *AppError
- func NewAlreadyExistsError(resource, id string) *AppError
- func NewAppError(code ErrorCode, message string) *AppError
- func NewConfigError(key, reason string) *AppError
- func NewDatabaseError(operation string, err error) *AppError
- func NewForbiddenError(resource string) *AppError
- func NewInternalError(message string) *AppError
- func NewInvalidInputError(field, value string) *AppError
- func NewMissingRequiredError(field string) *AppError
- func NewNetworkError(message string) *AppError
- func NewNotFoundError(resource, id string) *AppError
- func NewPanicError(recovered interface{}) *AppError
- func NewParsingError(format, input string) *AppError
- func NewProcessingError(message string) *AppError
- func NewRateLimitError(limit int, window time.Duration) *AppError
- func NewTimeoutError(operation string, timeout time.Duration) *AppError
- func NewUnauthorizedError(message string) *AppError
- func NewValidationError(message string) *AppError
- func Newf(code ErrorCode, format string, args ...interface{}) *AppError
- func Wrap(err error, code ErrorCode, message string) *AppError
- func Wrapf(err error, code ErrorCode, format string, args ...interface{}) *AppError
- func (e *AppError) Error() string
- func (e *AppError) GetCode() ErrorCode
- func (e *AppError) GetSeverity() Severity
- func (e *AppError) Is(target error) bool
- func (e *AppError) IsRetryable() bool
- func (e *AppError) Unwrap() error
- func (e *AppError) WithContext(key string, value interface{}) *AppError
- func (e *AppError) WithRequestID(requestID string) *AppError
- func (e *AppError) WithUserID(userID string) *AppError
- type ErrorCode
- type ErrorList
- type Severity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHTTPStatus ¶
GetHTTPStatus returns the appropriate HTTP status code for an error
Types ¶
type AppError ¶
type AppError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Cause error `json:"-"`
Context map[string]interface{} `json:"context,omitempty"`
Severity Severity `json:"severity"`
Timestamp time.Time `json:"timestamp"`
StackTrace string `json:"stack_trace,omitempty"`
RequestID string `json:"request_id,omitempty"`
UserID string `json:"user_id,omitempty"`
Retryable bool `json:"retryable"`
}
AppError represents a structured application error
func GetAppError ¶
GetAppError extracts an AppError from an error chain
func NewAlreadyExistsError ¶
func NewAppError ¶
NewAppError creates a new AppError with the given code and message
func NewConfigError ¶
Configuration error constructors
func NewDatabaseError ¶
Database error constructors
func NewForbiddenError ¶
func NewInvalidInputError ¶
func NewMissingRequiredError ¶
func NewNotFoundError ¶
Resource error constructors
func NewPanicError ¶
func NewPanicError(recovered interface{}) *AppError
func NewParsingError ¶
func NewProcessingError ¶
Processing error constructors
func NewUnauthorizedError ¶
Authentication error constructors
func NewValidationError ¶
Validation error constructors
func (*AppError) GetSeverity ¶
GetSeverity returns the error severity
func (*AppError) IsRetryable ¶
IsRetryable returns whether the error is retryable
func (*AppError) WithContext ¶
WithContext adds context information to the error
func (*AppError) WithRequestID ¶
WithRequestID adds a request ID to the error
func (*AppError) WithUserID ¶
WithUserID adds a user ID to the error
type ErrorCode ¶
type ErrorCode string
ErrorCode represents different categories of errors
const ( // General errors INTERNAL_ERROR ErrorCode = "INTERNAL_ERROR" INVALID_INPUT ErrorCode = "INVALID_INPUT" UNAUTHORIZED ErrorCode = "UNAUTHORIZED" FORBIDDEN ErrorCode = "FORBIDDEN" RATE_LIMITED ErrorCode = "RATE_LIMITED" NOT_FOUND_ERROR ErrorCode = "NOT_FOUND_ERROR" VALIDATION_ERROR ErrorCode = "VALIDATION_ERROR" // Package scanning errors PACKAGE_NOT_FOUND ErrorCode = "PACKAGE_NOT_FOUND" SCAN_FAILED ErrorCode = "SCAN_FAILED" INVALID_PACKAGE ErrorCode = "INVALID_PACKAGE" // Database errors DB_CONNECTION_ERROR ErrorCode = "DB_CONNECTION_ERROR" DB_QUERY_ERROR ErrorCode = "DB_QUERY_ERROR" DB_TRANSACTION_ERROR ErrorCode = "DB_TRANSACTION_ERROR" // Cache errors CACHE_ERROR ErrorCode = "CACHE_ERROR" CACHE_MISS ErrorCode = "CACHE_MISS" // ML/AI errors ML_MODEL_ERROR ErrorCode = "ML_MODEL_ERROR" ML_PREDICTION_ERROR ErrorCode = "ML_PREDICTION_ERROR" // Configuration errors CONFIG_ERROR ErrorCode = "CONFIG_ERROR" CONFIG_VALIDATION_ERROR ErrorCode = "CONFIG_VALIDATION_ERROR" // Input validation errors ErrCodeValidation ErrorCode = "VALIDATION_ERROR" ErrCodeInvalidInput ErrorCode = "INVALID_INPUT" ErrCodeMissingRequired ErrorCode = "MISSING_REQUIRED" // Network and external service errors ErrCodeNetwork ErrorCode = "NETWORK_ERROR" ErrCodeTimeout ErrorCode = "TIMEOUT_ERROR" ErrCodeRateLimit ErrorCode = "RATE_LIMIT_ERROR" // Resource errors ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeAlreadyExists ErrorCode = "ALREADY_EXISTS" ErrCodePermissionDenied ErrorCode = "PERMISSION_DENIED" ErrCodeQuotaExceeded ErrorCode = "QUOTA_EXCEEDED" // Processing errors ErrCodeProcessing ErrorCode = "PROCESSING_ERROR" ErrCodeParsing ErrorCode = "PARSING_ERROR" ErrCodeEncoding ErrorCode = "ENCODING_ERROR" ErrCodeDecoding ErrorCode = "DECODING_ERROR" // Database errors ErrCodeDatabase ErrorCode = "DATABASE_ERROR" ErrCodeTransaction ErrorCode = "TRANSACTION_ERROR" ErrCodeConstraint ErrorCode = "CONSTRAINT_ERROR" // Authentication and authorization errors ErrCodeAuth ErrorCode = "AUTH_ERROR" ErrCodeForbidden ErrorCode = "FORBIDDEN" ErrCodeTokenExpired ErrorCode = "TOKEN_EXPIRED" // Configuration errors ErrCodeConfig ErrorCode = "CONFIG_ERROR" ErrCodeMissingConfig ErrorCode = "MISSING_CONFIG" ErrCodeInvalidConfig ErrorCode = "INVALID_CONFIG" // Internal system errors ErrCodeInternal ErrorCode = "INTERNAL_ERROR" ErrCodePanic ErrorCode = "PANIC_ERROR" ErrCodeUnknown ErrorCode = "UNKNOWN_ERROR" )
type ErrorList ¶
type ErrorList struct {
Errors []*AppError `json:"errors"`
}
ErrorList represents a collection of errors
type Severity ¶
type Severity string
Severity represents the severity level of an error
func GetSeverity ¶
GetSeverity returns the severity of an error