errors

package module
v1.0.10 Latest Latest
Warning

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

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

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// configuration related errors
	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")

	// configuration center errors
	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")

	// network related errors
	ErrInvalidIP        = errors.New("invalid IP address")
	ErrInvalidPort      = errors.New("invalid port")
	ErrConnectionFailed = errors.New("connection failed")

	// protocol related errors
	ErrInvalidTLSVersion  = errors.New("invalid TLS version")
	ErrInvalidCipherSuite = errors.New("invalid cipher suite")
	ErrInvalidExtension   = errors.New("invalid extension")

	// input validation errors
	ErrInvalidInput  = errors.New("invalid input")
	ErrEmptyInput    = errors.New("empty input")
	ErrInputTooLarge = errors.New("input too large")
	ErrRequiredField = errors.New("required field is missing")

	// internal errors
	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 type assertion (compatible with standard library)

func Is

func Is(err, target error) bool

Is checks if error matches (compatible with standard library)

func IsClientHelloSpecNotImplemented

func IsClientHelloSpecNotImplemented(err error) bool

IsClientHelloSpecNotImplemented checks if error indicates profile does not implement ClientHelloSpec.

func IsCode added in v1.0.6

func IsCode(err error, code ErrorCode) bool

IsCode checks if error matches specified error code

func IsConfigError

func IsConfigError(err error) bool

IsConfigError checks if it is a configuration error

func IsInvalidInput

func IsInvalidInput(err error) bool

IsInvalidInput checks if it is an "invalid input" error

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if it is a "not found" error

func New

func New(text string) error

New creates new error (compatible with standard library)

func NewConfigError

func NewConfigError(op string, err error) error

NewConfigError createconfigurationerror

func NewNetworkError

func NewNetworkError(op string, err error) error

NewNetworkError creates network error

func NewNotFoundError

func NewNotFoundError(resource string, identifier string) error

NewNotFoundError creates not found error

func NewProtocolError

func NewProtocolError(protocol string, err error) error

NewProtocolError createprotocolerror

func NewValidationError

func NewValidationError(field string, reason string) error

NewValidationError createverifyerror

func Newf

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

Newf creates error using formatted string

func Wrap

func Wrap(err error, context string) error

Wrap wraps error and adds context

Example

ExampleWrap example: error wrapping

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 wraps error using formatted string

Types

type CategorizedError

type CategorizedError struct {
	Category ErrorCategory
	Err      error
	Details  string
}

CategorizedError categorized error

func NewCategorizedError

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

NewCategorizedError creates categorized error

Example

ExampleNewCategorizedError example:classifyerror

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 CodeError added in v1.0.6

type CodeError struct {
	Code    ErrorCode
	Message string
	Cause   error
	Details map[string]any
}

CodeError error with error code

func ConfigNotLoaded added in v1.0.6

func ConfigNotLoaded(path string) *CodeError

ConfigNotLoaded creates configuration not loaded error

func Internal added in v1.0.6

func Internal(op string, cause error) *CodeError

Internal creates internal error

func InvalidInput added in v1.0.6

func InvalidInput(field string, reason string) *CodeError

InvalidInput creates invalid input error

func NewError added in v1.0.6

func NewError(code ErrorCode, message string) *CodeError

NewError creates error with error code

func NewErrorWithCause added in v1.0.6

func NewErrorWithCause(code ErrorCode, message string, cause error) *CodeError

NewErrorWithCause creates error with error code and cause

func ProfileInvalid added in v1.0.6

func ProfileInvalid(id string, reason string) *CodeError

ProfileInvalid creates Profile invalid error

func ProfileNotFound added in v1.0.6

func ProfileNotFound(id string) *CodeError

ProfileNotFound creates Profile not found error

func ProfileRemoveDefault added in v1.0.6

func ProfileRemoveDefault(id string) *CodeError

ProfileRemoveDefault creates error for cannot remove default Profile

func RequiredField added in v1.0.6

func RequiredField(field string) *CodeError

RequiredField creates required field missing error

func Timeout added in v1.0.6

func Timeout(op string, duration any) *CodeError

Timeout createtimeouterror

func (*CodeError) Error added in v1.0.6

func (e *CodeError) Error() string

func (*CodeError) Unwrap added in v1.0.6

func (e *CodeError) Unwrap() error

func (*CodeError) WithDetail added in v1.0.6

func (e *CodeError) WithDetail(key string, value any) *CodeError

WithDetail adds detailed information

type ErrorCategory

type ErrorCategory string

ErrorCategory errorclassify

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

type ErrorCode added in v1.0.6

type ErrorCode string

ErrorCode error code type

const (
	// system level errors (SYS)
	ErrCodeSystem     ErrorCode = "SYS001"
	ErrCodeNotFound   ErrorCode = "SYS002"
	ErrCodeInvalidArg ErrorCode = "SYS003"
	ErrCodeTimeout    ErrorCode = "SYS004"
	ErrCodeCancelled  ErrorCode = "SYS005"
	ErrCodeInternal   ErrorCode = "SYS006"
	ErrCodeNotImpl    ErrorCode = "SYS007"

	// Profile related errors (PRF)
	ErrCodeProfileNotFound      ErrorCode = "PRF001"
	ErrCodeProfileInvalid       ErrorCode = "PRF002"
	ErrCodeProfileExists        ErrorCode = "PRF003"
	ErrCodeProfileLoadFailed    ErrorCode = "PRF004"
	ErrCodeProfileSaveFailed    ErrorCode = "PRF005"
	ErrCodeProfileNoDefault     ErrorCode = "PRF006"
	ErrCodeProfileRemoveDefault ErrorCode = "PRF007"

	// configuration related errors (CFG)
	ErrCodeConfigNotLoaded    ErrorCode = "CFG001"
	ErrCodeConfigValidation   ErrorCode = "CFG002"
	ErrCodeConfigPathNotFound ErrorCode = "CFG003"
	ErrCodeConfigExists       ErrorCode = "CFG004"
	ErrCodeConfigVersion      ErrorCode = "CFG005"

	// network related errors (NET)
	ErrCodeNetInvalidIP   ErrorCode = "NET001"
	ErrCodeNetInvalidPort ErrorCode = "NET002"
	ErrCodeNetConnect     ErrorCode = "NET003"
	ErrCodeNetTimeout     ErrorCode = "NET004"

	// protocol related errors (PRT)
	ErrCodeProtoTLSVersion  ErrorCode = "PRT001"
	ErrCodeProtoCipherSuite ErrorCode = "PRT002"
	ErrCodeProtoExtension   ErrorCode = "PRT003"
	ErrCodeProtoInvalidSpec ErrorCode = "PRT004"

	// input validation errors (INP)
	ErrCodeInputInvalid  ErrorCode = "INP001"
	ErrCodeInputEmpty    ErrorCode = "INP002"
	ErrCodeInputTooLarge ErrorCode = "INP003"
	ErrCodeInputRequired ErrorCode = "INP004"

	// cache related errors (CCH)
	ErrCodeCacheNotFound ErrorCode = "CCH001"
	ErrCodeCacheExpired  ErrorCode = "CCH002"

	// ML related errors (ML)
	ErrCodeMLModelNotFound ErrorCode = "ML001"
	ErrCodeMLPrediction    ErrorCode = "ML002"

	// plugin related errors (PLG)
	ErrCodePluginNotFound ErrorCode = "PLG001"
	ErrCodePluginInit     ErrorCode = "PLG002"
)

func GetCode added in v1.0.6

func GetCode(err error) ErrorCode

GetCode gets error code

Jump to

Keyboard shortcuts

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