errors

package
v0.46.7 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides standardized error handling for StackKit operations. It implements a hierarchical error classification system that allows for proper error propagation, user-friendly messages, and automated recovery.

Error Categories:

  • ValidationError: Configuration or input validation failures
  • InfrastructureError: Docker, network, or platform failures
  • DeploymentError: Deployment-specific failures
  • ResourceError: Resource availability (ports, memory, etc.)
  • AuthError: Authentication/authorization failures
  • DependencyError: External dependency failures

Usage:

err := errors.NewValidationError("port_conflict", "Port 80 is already in use",
    errors.WithField("port", 80),
    errors.WithSuggestion("Use a different port in the range 10000-19999"),
    errors.WithAutoFix(func() error { return autoAdjustPort(80) }),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorCategory

type ErrorCategory string

ErrorCategory classifies the type of error for appropriate handling

const (
	CategoryValidation     ErrorCategory = "validation"
	CategoryInfrastructure ErrorCategory = "infrastructure"
	CategoryDeployment     ErrorCategory = "deployment"
	CategoryResource       ErrorCategory = "resource"
	CategoryAuth           ErrorCategory = "auth"
	CategoryDependency     ErrorCategory = "dependency"
	CategoryUnknown        ErrorCategory = "unknown"
)

type ErrorHandler

type ErrorHandler struct {
	AutoRecover bool
	OnError     func(*StackKitError)
	OnFatal     func(*StackKitError)
}

ErrorHandler provides centralized error handling with recovery strategies

func (*ErrorHandler) Handle

func (h *ErrorHandler) Handle(err error) error

Handle processes an error according to its severity and recovery options

type ErrorOption

type ErrorOption func(*StackKitError)

ErrorOption configures a StackKitError

func WithAutoFix

func WithAutoFix(fix func() error) ErrorOption

WithAutoFix sets an auto-fix function

func WithCause

func WithCause(cause error) ErrorOption

WithCause sets the underlying cause

func WithField

func WithField(key string, value interface{}) ErrorOption

WithField adds a context field to the error

func WithSeverity

func WithSeverity(severity Severity) ErrorOption

WithSeverity sets the error severity

func WithSuggestion

func WithSuggestion(suggestion string) ErrorOption

WithSuggestion adds a user-facing suggestion

type Severity

type Severity string

Severity indicates how critical the error is

const (
	SeverityFatal   Severity = "fatal"   // Cannot continue, manual intervention required
	SeverityError   Severity = "error"   // Operation failed, can retry or fix
	SeverityWarning Severity = "warning" // Non-critical issue, can proceed
	SeverityInfo    Severity = "info"    // Informational, for logging only
)

type StackKitError

type StackKitError struct {
	Category    ErrorCategory
	Code        string
	Message     string
	Cause       error
	Fields      map[string]interface{}
	Suggestions []string
	AutoFix     func() error
	Severity    Severity
	Recoverable bool
}

StackKitError is the base error type for all StackKit operations

func DeploymentVerificationError

func DeploymentVerificationError(hostCount, vmCount int) *StackKitError

func DockerNotAvailableError

func DockerNotAvailableError() *StackKitError

func New

func New(category ErrorCategory, code string, message string, opts ...ErrorOption) *StackKitError

New creates a new StackKitError with the given category and code

func NewAuthError

func NewAuthError(code string, message string, opts ...ErrorOption) *StackKitError

func NewDependencyError

func NewDependencyError(code string, message string, opts ...ErrorOption) *StackKitError

func NewDeploymentError

func NewDeploymentError(code string, message string, opts ...ErrorOption) *StackKitError

func NewInfrastructureError

func NewInfrastructureError(code string, message string, opts ...ErrorOption) *StackKitError

func NewResourceError

func NewResourceError(code string, message string, opts ...ErrorOption) *StackKitError

func NewValidationError

func NewValidationError(code string, message string, opts ...ErrorOption) *StackKitError

func PortConflictError

func PortConflictError(port int, service string) *StackKitError

func VMNotHealthyError

func VMNotHealthyError() *StackKitError

func (*StackKitError) Error

func (e *StackKitError) Error() string

func (*StackKitError) IsRecoverable

func (e *StackKitError) IsRecoverable() bool

IsRecoverable returns true if the error can be automatically fixed

func (*StackKitError) TryAutoFix

func (e *StackKitError) TryAutoFix() error

TryAutoFix attempts to automatically fix the error

func (*StackKitError) Unwrap

func (e *StackKitError) Unwrap() error

Jump to

Keyboard shortcuts

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