errors

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides unified error handling functionality. Defines application error types and predefined error variables, supports error wrapping and context information.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Redis related errors
	ErrRedisConnection = &AppError{
		Code:    "REDIS_CONN_ERR",
		Message: "Redis 连接失败",
	}
	ErrRedisOperation = &AppError{
		Code:    "REDIS_OP_ERR",
		Message: "Redis 操作失败",
	}
	ErrRedisLock = &AppError{
		Code:    "REDIS_LOCK_ERR",
		Message: "Redis 分布式锁操作失败",
	}

	// Configuration related errors
	ErrConfigLoad = &AppError{
		Code:    "CONFIG_LOAD_ERR",
		Message: "配置加载失败",
	}
	ErrConfigValidation = &AppError{
		Code:    "CONFIG_VALIDATION_ERR",
		Message: "配置验证失败",
	}
	ErrConfigParse = &AppError{
		Code:    "CONFIG_PARSE_ERR",
		Message: "配置解析失败",
	}

	// Application initialization errors
	ErrAppInit = &AppError{
		Code:    "APP_INIT_ERR",
		Message: "应用初始化失败",
	}

	// HTTP related errors
	ErrHTTPRequest = &AppError{
		Code:    "HTTP_REQ_ERR",
		Message: "HTTP 请求失败",
	}
	ErrHTTPResponse = &AppError{
		Code:    "HTTP_RESP_ERR",
		Message: "HTTP 响应处理失败",
	}

	// Data related errors
	ErrDataLoad = &AppError{
		Code:    "DATA_LOAD_ERR",
		Message: "数据加载失败",
	}
	ErrDataParse = &AppError{
		Code:    "DATA_PARSE_ERR",
		Message: "数据解析失败",
	}

	// Cache related errors
	ErrCacheOperation = &AppError{
		Code:    "CACHE_OP_ERR",
		Message: "缓存操作失败",
	}

	// Parameter validation errors
	ErrInvalidParameter = &AppError{
		Code:    "INVALID_PARAM_ERR",
		Message: "无效的参数",
	}

	// Task execution errors
	ErrTaskExecution = &AppError{
		Code:    "TASK_EXEC_ERR",
		Message: "任务执行失败",
	}
)

Predefined error types

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Code    string // Error code (16 bytes)
	Message string // Error message (16 bytes)
	Err     error  // Underlying error (16 bytes interface)
}

AppError application error type, provides unified error handling

func Wrap

func Wrap(err error, code, message string) *AppError

Wrap wraps error, provides context information

func Wrapf

func Wrapf(err error, code, format string, args ...interface{}) *AppError

Wrapf wraps error using formatted string

func (*AppError) Error

func (e *AppError) Error() string

Error implements error interface

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap implements error wrapping interface, supports errors.Unwrap

func (*AppError) WithError

func (e *AppError) WithError(err error) *AppError

WithError wraps underlying error

func (*AppError) WithLanguage added in v0.2.0

func (e *AppError) WithLanguage(r *http.Request) *AppError

WithLanguage gets localized error message based on request context If request is nil or language cannot be obtained, returns original message

func (*AppError) WithMessage

func (e *AppError) WithMessage(msg string) *AppError

WithMessage adds custom message

Jump to

Keyboard shortcuts

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