errors

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package errors provides structured error handling for scanorama operations. It defines error codes, error types, and provides utilities for creating and handling errors with context and structured information.

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 has a specific error code.

func IsConflict

func IsConflict(err error) bool

IsConflict checks if an error indicates a resource conflict.

func IsFatal

func IsFatal(err error) bool

IsFatal determines if an error indicates a fatal condition that should stop execution.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if an error indicates a resource was not found.

func IsRetryable

func IsRetryable(err error) bool

IsRetryable determines if an error indicates a retryable condition.

Types

type ConfigError

type ConfigError struct {
	Code    ErrorCode
	Message string
	Field   string
	Value   interface{}
	Cause   error
}

ConfigError represents configuration-related errors.

func ErrConfigInvalid

func ErrConfigInvalid(field string, value interface{}) *ConfigError

ErrConfigInvalid creates an error for invalid configuration.

func ErrConfigMissing

func ErrConfigMissing(field string) *ConfigError

ErrConfigMissing creates an error for missing required configuration.

func NewConfigError

func NewConfigError(code ErrorCode, message string) *ConfigError

NewConfigError creates a new configuration error.

func NewConfigFieldError

func NewConfigFieldError(code ErrorCode, message, field string, value interface{}) *ConfigError

NewConfigFieldError creates a configuration error for a specific field.

func WrapConfigError

func WrapConfigError(code ErrorCode, message string, err error) *ConfigError

WrapConfigError wraps an existing error as a configuration error.

func (*ConfigError) Error

func (e *ConfigError) Error() string

Error implements the error interface.

func (*ConfigError) Unwrap

func (e *ConfigError) Unwrap() error

Unwrap returns the underlying error.

type DatabaseError

type DatabaseError struct {
	Code      ErrorCode
	Message   string
	Operation string
	Query     string
	Cause     error
	Context   map[string]interface{}
}

DatabaseError represents database-related errors.

func ErrDatabaseConnection

func ErrDatabaseConnection(err error) *DatabaseError

ErrDatabaseConnection creates an error for database connection failures.

func ErrDatabaseQuery

func ErrDatabaseQuery(query string, err error) *DatabaseError

ErrDatabaseQuery creates an error for database query failures.

func NewDatabaseError

func NewDatabaseError(code ErrorCode, message string) *DatabaseError

NewDatabaseError creates a new database error.

func WrapDatabaseError

func WrapDatabaseError(code ErrorCode, message string, err error) *DatabaseError

WrapDatabaseError wraps an existing error as a database error.

func (*DatabaseError) Error

func (e *DatabaseError) Error() string

Error implements the error interface.

func (*DatabaseError) Unwrap

func (e *DatabaseError) Unwrap() error

Unwrap returns the underlying error.

func (*DatabaseError) WithQuery

func (e *DatabaseError) WithQuery(query string) *DatabaseError

WithQuery adds the SQL query that caused the error.

type DiscoveryError

type DiscoveryError struct {
	Code    ErrorCode
	Message string
	Network string
	Method  string
	Cause   error
	Context map[string]interface{}
}

DiscoveryError represents network discovery errors.

func ErrDiscoveryFailed

func ErrDiscoveryFailed(network string, err error) *DiscoveryError

ErrDiscoveryFailed creates an error for discovery failures.

func NewDiscoveryError

func NewDiscoveryError(code ErrorCode, message string) *DiscoveryError

NewDiscoveryError creates a new discovery error.

func WrapDiscoveryError

func WrapDiscoveryError(code ErrorCode, message string, err error) *DiscoveryError

WrapDiscoveryError wraps an existing error as a discovery error.

func (*DiscoveryError) Error

func (e *DiscoveryError) Error() string

Error implements the error interface.

func (*DiscoveryError) Unwrap

func (e *DiscoveryError) Unwrap() error

Unwrap returns the underlying error.

type ErrorCode

type ErrorCode string

ErrorCode represents different types of errors that can occur.

const (
	// General errors.
	CodeUnknown       ErrorCode = "UNKNOWN"
	CodeValidation    ErrorCode = "VALIDATION"
	CodeConfiguration ErrorCode = "CONFIGURATION"
	CodeTimeout       ErrorCode = "TIMEOUT"
	CodeCanceled      ErrorCode = "CANCELED"
	CodePermission    ErrorCode = "PERMISSION"

	// Network and scanning errors.
	CodeNetworkUnreachable ErrorCode = "NETWORK_UNREACHABLE"
	CodeHostUnreachable    ErrorCode = "HOST_UNREACHABLE"
	CodePortClosed         ErrorCode = "PORT_CLOSED"
	CodeScanFailed         ErrorCode = "SCAN_FAILED"
	CodeDiscoveryFailed    ErrorCode = "DISCOVERY_FAILED"
	CodeTargetInvalid      ErrorCode = "TARGET_INVALID"

	// Database errors.
	CodeDatabaseConnection ErrorCode = "DATABASE_CONNECTION"
	CodeDatabaseQuery      ErrorCode = "DATABASE_QUERY"
	CodeDatabaseMigration  ErrorCode = "DATABASE_MIGRATION"
	CodeDatabaseTimeout    ErrorCode = "DATABASE_TIMEOUT"

	// File system errors.
	CodeFileNotFound    ErrorCode = "FILE_NOT_FOUND"
	CodeFilePermission  ErrorCode = "FILE_PERMISSION"
	CodeDirectoryCreate ErrorCode = "DIRECTORY_CREATE"

	// Service errors.
	CodeServiceUnavailable ErrorCode = "SERVICE_UNAVAILABLE"
	CodeServiceTimeout     ErrorCode = "SERVICE_TIMEOUT"
	CodeRateLimited        ErrorCode = "RATE_LIMITED"

	// Generic resource errors.
	CodeNotFound ErrorCode = "NOT_FOUND"
	CodeConflict ErrorCode = "CONFLICT"
)

func GetCode

func GetCode(err error) ErrorCode

GetCode extracts the error code from an error if it has one.

type ScanError

type ScanError struct {
	Code      ErrorCode
	Message   string
	Target    string
	Operation string
	Cause     error
	Context   map[string]interface{}
}

ScanError represents an error that occurred during scanning operations.

func ErrConflict

func ErrConflict(resource string) *ScanError

ErrConflict creates a generic conflict error.

func ErrConflictWithReason

func ErrConflictWithReason(resource, reason string) *ScanError

ErrConflictWithReason creates a conflict error with specific reason.

func ErrHostUnreachable

func ErrHostUnreachable(target string) *ScanError

ErrHostUnreachable creates an error for unreachable hosts.

func ErrInvalidTarget

func ErrInvalidTarget(target string) *ScanError

ErrInvalidTarget creates an error for invalid scan targets.

func ErrNotFound

func ErrNotFound(resource string) *ScanError

ErrNotFound creates a generic not found error.

func ErrNotFoundWithID

func ErrNotFoundWithID(resource, id string) *ScanError

ErrNotFoundWithID creates a not found error with specific ID.

func ErrScanTimeout

func ErrScanTimeout(target string) *ScanError

ErrScanTimeout creates an error for scan timeouts.

func NewScanError

func NewScanError(code ErrorCode, message string) *ScanError

NewScanError creates a new scan error with the specified code and message.

func NewScanErrorWithTarget

func NewScanErrorWithTarget(code ErrorCode, message, target string) *ScanError

NewScanErrorWithTarget creates a scan error for a specific target.

func WrapScanError

func WrapScanError(code ErrorCode, message string, err error) *ScanError

WrapScanError wraps an existing error as a scan error.

func WrapScanErrorWithTarget

func WrapScanErrorWithTarget(code ErrorCode, message, target string, err error) *ScanError

WrapScanErrorWithTarget wraps an error with target information.

func (*ScanError) Error

func (e *ScanError) Error() string

Error implements the error interface.

func (*ScanError) Unwrap

func (e *ScanError) Unwrap() error

Unwrap returns the underlying error for error unwrapping.

func (*ScanError) WithContext

func (e *ScanError) WithContext(key string, value interface{}) *ScanError

WithContext adds context information to the error.

Jump to

Keyboard shortcuts

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