errors

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: BSD-3-Clause Imports: 3 Imported by: 10

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// 配置相关错误
	ErrProfileNotFound               = errors.New("profile not found")
	ErrInvalidFingerprint            = errors.New("invalid fingerprint format")
	ErrClientHelloSpecNotImplemented = errors.New("client hello spec not implemented")
	ErrInvalidUserAgent              = errors.New("invalid user agent")
	ErrNoProfilesAvailable           = errors.New("no profiles available")
	ErrUnsupportedBrowser            = errors.New("unsupported browser")

	// 配置中心错误
	ErrConfigNotLoaded     = errors.New("config not loaded")
	ErrConfigValidation    = errors.New("config validation failed")
	ErrConfigPathNotFound  = errors.New("config path not found")
	ErrConfigAlreadyExists = errors.New("config already exists")
	ErrVersionNotFound     = errors.New("version not found")

	// 网络相关错误
	ErrInvalidIP        = errors.New("invalid IP address")
	ErrInvalidPort      = errors.New("invalid port")
	ErrConnectionFailed = errors.New("connection failed")

	// 协议相关错误
	ErrInvalidTLSVersion  = errors.New("invalid TLS version")
	ErrInvalidCipherSuite = errors.New("invalid cipher suite")
	ErrInvalidExtension   = errors.New("invalid extension")

	// 输入验证错误
	ErrInvalidInput  = errors.New("invalid input")
	ErrEmptyInput    = errors.New("empty input")
	ErrInputTooLarge = errors.New("input too large")
	ErrRequiredField = errors.New("required field is missing")

	// 内部错误
	ErrInternal       = errors.New("internal error")
	ErrNotImplemented = errors.New("not implemented")
	ErrTimeout        = errors.New("operation timeout")
	ErrCancelled      = errors.New("operation cancelled")
)

Functions

func As

func As(err error, target interface{}) bool

As 类型断言(兼容标准库)

func Is

func Is(err, target error) bool

Is 检查错误是否匹配(兼容标准库)

func IsClientHelloSpecNotImplemented

func IsClientHelloSpecNotImplemented(err error) bool

IsClientHelloSpecNotImplemented 判断错误是否表示 profile 未实现 ClientHelloSpec。

func IsConfigError

func IsConfigError(err error) bool

IsConfigError 检查是否为配置类错误

func IsInvalidInput

func IsInvalidInput(err error) bool

IsInvalidInput 检查是否为"无效输入"类错误

func IsNotFound

func IsNotFound(err error) bool

IsNotFound 检查是否为"未找到"类错误

func New

func New(text string) error

New 创建新错误(兼容标准库)

func NewConfigError

func NewConfigError(op string, err error) error

NewConfigError 创建配置错误

func NewNetworkError

func NewNetworkError(op string, err error) error

NewNetworkError 创建网络错误

func NewNotFoundError

func NewNotFoundError(resource string, identifier string) error

NewNotFoundError 创建未找到错误

func NewProtocolError

func NewProtocolError(protocol string, err error) error

NewProtocolError 创建协议错误

func NewValidationError

func NewValidationError(field string, reason string) error

NewValidationError 创建验证错误

func Newf

func Newf(format string, args ...interface{}) error

Newf 使用格式化字符串创建错误

func Wrap

func Wrap(err error, context string) error

Wrap 包装错误并添加上下文

Example

ExampleWrap 示例:错误包装

baseErr := errors.New("file not found")
wrapped := Wrap(baseErr, "loading config")
fmt.Println(wrapped)
Output:
loading config: file not found

func Wrapf

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

Wrapf 使用格式化字符串包装错误

Types

type CategorizedError

type CategorizedError struct {
	Category ErrorCategory
	Err      error
	Details  string
}

CategorizedError 带分类的错误

func NewCategorizedError

func NewCategorizedError(category ErrorCategory, err error, details string) *CategorizedError

NewCategorizedError 创建带分类的错误

Example

ExampleNewCategorizedError 示例:分类错误

err := NewCategorizedError(CategoryConfig, ErrConfigNotLoaded, "missing file")
fmt.Println(err)
Output:
[config] config not loaded: missing file

func (*CategorizedError) Error

func (e *CategorizedError) Error() string

func (*CategorizedError) Unwrap

func (e *CategorizedError) Unwrap() error

type ErrorCategory

type ErrorCategory string

ErrorCategory 错误分类

const (
	CategoryConfig   ErrorCategory = "config"
	CategoryNetwork  ErrorCategory = "network"
	CategoryProtocol ErrorCategory = "protocol"
	CategoryInput    ErrorCategory = "input"
	CategoryInternal ErrorCategory = "internal"
	CategoryNotFound ErrorCategory = "not_found"
)

Jump to

Keyboard shortcuts

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