errors

package
v0.0.0-...-4b1b407 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleaningError

func CleaningError(message string) error

CleaningError creates cleaning operation error.

func ConfigLoadError

func ConfigLoadError(message string) error

ConfigLoadError creates config loading error.

func ConfigSaveError

func ConfigSaveError(message string) error

ConfigSaveError creates config saving error.

func ConfigValidateError

func ConfigValidateError(message string) error

ConfigValidateError creates config validation error.

func IsNixAvailable

func IsNixAvailable() bool

IsNixAvailable checks if Nix is available on the system.

func NixCommandError

func NixCommandError(message string) error

NixCommandError creates nix command error.

func ValidationError

func ValidationError(field, value, expected string) error

ValidationError creates validation error.

Types

type CleanWizardError

type CleanWizardError struct {
	Code      ErrorCode
	Level     ErrorLevel
	Message   string
	Operation string
	Details   *ErrorDetails `json:"details,omitempty"`
	Timestamp time.Time
	Stack     string
}

CleanWizardError represents structured error with context.

func HandleCommandError

func HandleCommandError(cmd *exec.Cmd, err error) *CleanWizardError

HandleCommandError standardizes command execution errors.

func HandleConfigError

func HandleConfigError(operation string, err error) *CleanWizardError

HandleConfigError standardizes configuration errors.

func HandleNixNotAvailable

func HandleNixNotAvailable(operation string) *CleanWizardError

HandleNixNotAvailable standardizes Nix availability errors.

func HandleValidationError

func HandleValidationError(operation string, err error) *CleanWizardError

HandleValidationError standardizes validation errors.

func HandleValidationErrorWithDetails

func HandleValidationErrorWithDetails(operation, field string, value any, reason string) *CleanWizardError

HandleValidationErrorWithDetails standardizes validation errors with detailed context.

func NewError

func NewError(code ErrorCode, message string) *CleanWizardError

NewError creates new CleanWizardError.

func NewErrorWithDetails

func NewErrorWithDetails(code ErrorCode, message string, details *ErrorDetails) *CleanWizardError

NewErrorWithDetails creates new CleanWizardError with context details.

func NewErrorWithLevel

func NewErrorWithLevel(code ErrorCode, level ErrorLevel, message string) *CleanWizardError

NewErrorWithLevel creates new CleanWizardError with custom level.

func WrapError

func WrapError(err error, code ErrorCode, operation string) *CleanWizardError

WrapError wraps existing error with CleanWizardError context.

func (*CleanWizardError) Error

func (e *CleanWizardError) Error() string

Error implements error interface.

func (*CleanWizardError) IsErrorCode

func (e *CleanWizardError) IsErrorCode(code ErrorCode) bool

IsErrorCode checks if error matches specific error code.

func (*CleanWizardError) IsLevel

func (e *CleanWizardError) IsLevel(level ErrorLevel) bool

IsLevel checks if error matches specific level.

func (*CleanWizardError) IsRetryable

func (e *CleanWizardError) IsRetryable() bool

IsRetryable checks if error is retryable.

func (*CleanWizardError) IsUserFriendly

func (e *CleanWizardError) IsUserFriendly() bool

IsUserFriendly checks if error is safe to show to users.

func (*CleanWizardError) Log

func (e *CleanWizardError) Log()

Log logs the error with appropriate level.

func (*CleanWizardError) Unwrap

func (e *CleanWizardError) Unwrap() error

Unwrap returns the underlying error for compatibility with Go 1.13+ error wrapping.

func (*CleanWizardError) WithDetail

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

WithDetail adds single detail to error.

func (*CleanWizardError) WithLevel

func (e *CleanWizardError) WithLevel(level ErrorLevel) *CleanWizardError

WithLevel sets error level.

func (*CleanWizardError) WithOperation

func (e *CleanWizardError) WithOperation(operation string) *CleanWizardError

WithOperation adds operation context to error.

type ErrorCode

type ErrorCode int

ErrorCode represents standardized error codes.

const (
	// General errors.
	ErrUnknown ErrorCode = iota
	ErrInvalidInput
	ErrNotFound
	ErrPermissionDenied
	ErrTimeout

	// Configuration errors.
	ErrConfigLoad
	ErrConfigSave
	ErrConfigValidation

	// Nix-specific errors.
	ErrNixNotAvailable
	ErrNixCommandFailed
	ErrNixStoreCorrupted

	// Cleaning errors.
	ErrCleaningFailed
	ErrCleaningTimeout
	ErrCleanupRollback
)

func (ErrorCode) String

func (e ErrorCode) String() string

String returns string representation of error code.

type ErrorDetails

type ErrorDetails struct {
	Field      string            `json:"field,omitempty"`
	Value      string            `json:"value,omitempty"`
	Expected   string            `json:"expected,omitempty"`
	Actual     string            `json:"actual,omitempty"`
	Operation  string            `json:"operation,omitempty"`
	FilePath   string            `json:"file_path,omitempty"`
	LineNumber int               `json:"line_number,omitempty"`
	RetryCount int               `json:"retry_count,omitempty"`
	Duration   string            `json:"duration,omitempty"`
	Metadata   map[string]string `json:"metadata,omitempty"`
}

ErrorDetails represents strongly-typed error context information.

type ErrorDetailsBuilder

type ErrorDetailsBuilder struct {
	// contains filtered or unexported fields
}

ErrorDetailsBuilder provides a fluent API for constructing ErrorDetails.

func NewErrorDetails

func NewErrorDetails() *ErrorDetailsBuilder

NewErrorDetails creates a new builder with an initialized metadata map.

func (*ErrorDetailsBuilder) Build

func (b *ErrorDetailsBuilder) Build() *ErrorDetails

Build returns the constructed ErrorDetails.

func (*ErrorDetailsBuilder) WithActual

func (b *ErrorDetailsBuilder) WithActual(actual string) *ErrorDetailsBuilder

WithActual sets the actual value for the error.

func (*ErrorDetailsBuilder) WithDuration

func (b *ErrorDetailsBuilder) WithDuration(duration string) *ErrorDetailsBuilder

WithDuration sets the duration string for the error.

func (*ErrorDetailsBuilder) WithExpected

func (b *ErrorDetailsBuilder) WithExpected(expected string) *ErrorDetailsBuilder

WithExpected sets the expected value for the error.

func (*ErrorDetailsBuilder) WithField

func (b *ErrorDetailsBuilder) WithField(field string) *ErrorDetailsBuilder

WithField sets the field name that caused the error.

func (*ErrorDetailsBuilder) WithFilePath

func (b *ErrorDetailsBuilder) WithFilePath(path string) *ErrorDetailsBuilder

WithFilePath sets the file path associated with the error.

func (*ErrorDetailsBuilder) WithLineNumber

func (b *ErrorDetailsBuilder) WithLineNumber(line int) *ErrorDetailsBuilder

WithLineNumber sets the line number associated with the error.

func (*ErrorDetailsBuilder) WithMetadata

func (b *ErrorDetailsBuilder) WithMetadata(key, value string) *ErrorDetailsBuilder

WithMetadata adds a key-value pair to the metadata map.

func (*ErrorDetailsBuilder) WithOperation

func (b *ErrorDetailsBuilder) WithOperation(operation string) *ErrorDetailsBuilder

WithOperation sets the operation context for the error.

func (*ErrorDetailsBuilder) WithRetryCount

func (b *ErrorDetailsBuilder) WithRetryCount(count int) *ErrorDetailsBuilder

WithRetryCount sets the retry count for the error.

func (*ErrorDetailsBuilder) WithValue

func (b *ErrorDetailsBuilder) WithValue(value string) *ErrorDetailsBuilder

WithValue sets the actual value that caused the error.

type ErrorLevel

type ErrorLevel int

ErrorLevel represents severity level of errors.

const (
	// Error levels.
	LevelDebug ErrorLevel = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelPanic
)

func (ErrorLevel) LogLevel

func (e ErrorLevel) LogLevel() string

LogLevel returns the corresponding logrus level.

func (ErrorLevel) String

func (e ErrorLevel) String() string

String returns string representation of error level.

Jump to

Keyboard shortcuts

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