errors

package
v0.0.0-...-a4f76d6 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors defines custom error types. pkg/errors/codes.go

Package errors defines custom error types. pkg/errors/errors.go

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 an AppError with a specific ErrorCode.

func New

func New(code ErrorCode, message string) error

New creates a new AppError with a given code and message.

func Wrap

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

Wrap creates a new AppError that wraps an existing error.

Types

type AppError

type AppError struct {
	Code    ErrorCode
	Message string
	Err     error // Original error, if any
}

AppError is a custom error type that includes an application-specific error code.

func IsAppError

func IsAppError(err error) (*AppError, bool)

IsAppError checks if an error is an AppError and returns it.

func (*AppError) Error

func (e *AppError) Error() string

Error implements the error interface for AppError.

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap returns the underlying error, allowing errors.Is and errors.As to work.

type ErrorCode

type ErrorCode int

ErrorCode represents a unique application-specific error code.

const (
	// Common error codes
	ErrCodeUnknown ErrorCode = iota // 0
	ErrCodeInvalidInput
	ErrCodeNotFound
	ErrCodeUnauthorized
	ErrCodeForbidden
	ErrCodeInternal
	ErrCodeServiceUnavailable

	// Configuration error codes
	ErrCodeConfigLoadFailed
	ErrCodeConfigValidationFailed

	// Network error codes
	ErrCodeNetworkConnectionFailed
	ErrCodeTimeout
)

func Code

func Code(err error) ErrorCode

Code returns the ErrorCode of an AppError, or ErrCodeUnknown if not an AppError.

func (ErrorCode) String

func (c ErrorCode) String() string

String returns the string representation of the ErrorCode.

Jump to

Keyboard shortcuts

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