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 ¶
- func IsCode(err error, code ErrorCode) bool
- func IsConflict(err error) bool
- func IsFatal(err error) bool
- func IsNotFound(err error) bool
- func IsRetryable(err error) bool
- type ConfigError
- func ErrConfigInvalid(field string, value interface{}) *ConfigError
- func ErrConfigMissing(field string) *ConfigError
- func NewConfigError(code ErrorCode, message string) *ConfigError
- func NewConfigFieldError(code ErrorCode, message, field string, value interface{}) *ConfigError
- func WrapConfigError(code ErrorCode, message string, err error) *ConfigError
- type DatabaseError
- type DiscoveryError
- type ErrorCode
- type ScanError
- func ErrConflict(resource string) *ScanError
- func ErrConflictWithReason(resource, reason string) *ScanError
- func ErrHostUnreachable(target string) *ScanError
- func ErrInvalidTarget(target string) *ScanError
- func ErrNotFound(resource string) *ScanError
- func ErrNotFoundWithID(resource, id string) *ScanError
- func ErrScanTimeout(target string) *ScanError
- func NewScanError(code ErrorCode, message string) *ScanError
- func NewScanErrorWithTarget(code ErrorCode, message, target string) *ScanError
- func WrapScanError(code ErrorCode, message string, err error) *ScanError
- func WrapScanErrorWithTarget(code ErrorCode, message, target string, err error) *ScanError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsConflict ¶
IsConflict checks if an error indicates a resource conflict.
func IsFatal ¶
IsFatal determines if an error indicates a fatal condition that should stop execution.
func IsNotFound ¶
IsNotFound checks if an error indicates a resource was not found.
func IsRetryable ¶
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. CodeServiceTimeout ErrorCode = "SERVICE_TIMEOUT" CodeRateLimited ErrorCode = "RATE_LIMITED" // Generic resource errors. CodeNotFound ErrorCode = "NOT_FOUND" CodeConflict ErrorCode = "CONFLICT" )
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 ¶
ErrConflict creates a generic conflict error.
func ErrConflictWithReason ¶
ErrConflictWithReason creates a conflict error with specific reason.
func ErrHostUnreachable ¶
ErrHostUnreachable creates an error for unreachable hosts.
func ErrInvalidTarget ¶
ErrInvalidTarget creates an error for invalid scan targets.
func ErrNotFound ¶
ErrNotFound creates a generic not found error.
func ErrNotFoundWithID ¶
ErrNotFoundWithID creates a not found error with specific ID.
func ErrScanTimeout ¶
ErrScanTimeout creates an error for scan timeouts.
func NewScanError ¶
NewScanError creates a new scan error with the specified code and message.
func NewScanErrorWithTarget ¶
NewScanErrorWithTarget creates a scan error for a specific target.
func WrapScanError ¶
WrapScanError wraps an existing error as a scan error.
func WrapScanErrorWithTarget ¶
WrapScanErrorWithTarget wraps an error with target information.
func (*ScanError) WithContext ¶
WithContext adds context information to the error.