errors

package module
v1.0.28 Latest Latest
Warning

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

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

Documentation

Overview

Package errors provides the unified error system for the fingerprint project. This is the canonical error package — all error codes, sentinel errors, error types, and helper functions live here. modules/core/errors.go re-exports a subset for backward compatibility.

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")
)
View Source
var (
	// ErrInvalidProfile invalid fingerprint profile
	ErrInvalidProfile = errors.New("invalid fingerprint profile")

	// ErrInvalidJA3Hash invalid JA3 hash
	ErrInvalidJA3Hash = errors.New("invalid JA3 hash")

	// ErrInvalidJA4Hash invalid JA4 hash
	ErrInvalidJA4Hash = errors.New("invalid JA4 hash")

	// ErrFeatureExtractionFailed feature extraction failed
	ErrFeatureExtractionFailed = errors.New("feature extraction failed")

	// ErrClassificationFailed classification failed
	ErrClassificationFailed = errors.New("classification failed")

	// ErrRiskAssessmentFailed risk assessment failed
	ErrRiskAssessmentFailed = errors.New("risk assessment failed")

	// ErrNilPointer nil pointer dereference
	ErrNilPointer = errors.New("nil pointer dereference")

	// ErrOutOfRange value out of range
	ErrOutOfRange = errors.New("value out of range")

	// ErrEmptyValue empty value
	ErrEmptyValue = errors.New("empty value")

	// ErrAlreadyExists resource already exists
	ErrAlreadyExists = errors.New("already exists")
)

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 IsCoreError added in v1.0.11

func IsCoreError(err error) bool

IsCoreError checks if the error is a CoreError

func IsErrorCode added in v1.0.11

func IsErrorCode(err error, code ErrorCode) bool

IsErrorCode checks if the error has the specified error code

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 CoreError added in v1.0.11

type CoreError struct {
	Code    ErrorCode
	Op      string
	Err     error
	Context string
}

CoreError is a structured error type with error code, operation, and context

func NewCodedError added in v1.0.11

func NewCodedError(code ErrorCode, op string, err error) *CoreError

NewCodedError creates a CoreError with error code

func NewCodedErrorf added in v1.0.11

func NewCodedErrorf(code ErrorCode, op, format string, args ...interface{}) *CoreError

NewCodedErrorf creates a CoreError with formatted context

func NewCoreError added in v1.0.11

func NewCoreError(op string, err error) *CoreError

NewCoreError creates a new CoreError with operation and underlying error

func NewCoreErrorWithContext added in v1.0.11

func NewCoreErrorWithContext(op, context string, err error) *CoreError

NewCoreErrorWithContext creates a CoreError with context

func WrapError added in v1.0.11

func WrapError(code ErrorCode, op string, err error, context string) *CoreError

WrapError wraps an error with error code, operation, and context

func WrapErrorf added in v1.0.11

func WrapErrorf(code ErrorCode, op string, err error, format string, args ...interface{}) *CoreError

WrapErrorf wraps an error with formatted context

func (*CoreError) CoreCategory added in v1.0.11

func (e *CoreError) CoreCategory() string

CoreCategory returns the error category string

func (*CoreError) CoreHTTPStatus added in v1.0.11

func (e *CoreError) CoreHTTPStatus() int

CoreHTTPStatus returns the HTTP status code for this error

func (*CoreError) Error added in v1.0.11

func (e *CoreError) Error() string

Error implements the error interface

func (*CoreError) Is added in v1.0.11

func (e *CoreError) Is(target error) bool

Is implements errors.Is matching by error code

func (*CoreError) Unwrap added in v1.0.11

func (e *CoreError) Unwrap() error

Unwrap returns the underlying error

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"
)
const (
	// Validation errors (VAL001-VAL099)
	ErrCodeInvalidInput   ErrorCode = "VAL001"
	ErrCodeRequiredField  ErrorCode = "VAL002"
	ErrCodeInvalidFormat  ErrorCode = "VAL003"
	ErrCodeOutOfRange     ErrorCode = "VAL004"
	ErrCodeNilPointer     ErrorCode = "VAL005"
	ErrCodeInvalidType    ErrorCode = "VAL006"
	ErrCodeEmptyValue     ErrorCode = "VAL007"
	ErrCodeInvalidLength  ErrorCode = "VAL008"
	ErrCodeInvalidCharset ErrorCode = "VAL009"
	ErrCodeInvalidPattern ErrorCode = "VAL010"

	// Not Found errors (NTF001-NTF099)
	ErrCodeProfileNTF  ErrorCode = "NTF001"
	ErrCodeResourceNTF ErrorCode = "NTF002"
	ErrCodeKeyNTF      ErrorCode = "NTF003"
	ErrCodeFileNTF     ErrorCode = "NTF004"
	ErrCodeRouteNTF    ErrorCode = "NTF005"

	// Security errors (SEC001-SEC099)
	ErrCodeSecurityError       ErrorCode = "SEC001"
	ErrCodeAuthFailed          ErrorCode = "SEC002"
	ErrCodeUnauthorized        ErrorCode = "SEC003"
	ErrCodeForbidden           ErrorCode = "SEC004"
	ErrCodeInvalidToken        ErrorCode = "SEC005"
	ErrCodeReplayAttack        ErrorCode = "SEC006"
	ErrCodeFingerprintMismatch ErrorCode = "SEC007"
	ErrCodeInvalidTLSVersion   ErrorCode = "SEC008"
	ErrCodeInvalidJA3Hash      ErrorCode = "SEC009"
	ErrCodeInvalidJA4Hash      ErrorCode = "SEC010"
)

func GetCode added in v1.0.6

func GetCode(err error) ErrorCode

GetCode gets error code

func GetErrorCode added in v1.0.11

func GetErrorCode(err error) ErrorCode

GetErrorCode returns the ErrorCode from a CoreError, or empty string

func (ErrorCode) Category added in v1.0.11

func (ec ErrorCode) Category() string

Category returns the error code category string

func (ErrorCode) HTTPStatus added in v1.0.11

func (ec ErrorCode) HTTPStatus() int

HTTPStatus returns the HTTP status code for the error code category

Jump to

Keyboard shortcuts

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