Documentation
¶
Overview ¶
Package errors provides common error handling utilities for the Doku CLI. It includes error types, error formatting helpers, and common error messages.
Index ¶
- Variables
- func As(err error, target interface{}) bool
- func Is(err, target error) bool
- func IsAlreadyExists(err error) bool
- func IsNotFound(err error) bool
- func IsPermissionDenied(err error) bool
- func LogOnError(err error, format string, args ...interface{})
- func Must(err error)
- func MustValue[T any](value T, err error) T
- func PrintError(format string, args ...interface{})
- func PrintErrorf(format string, args ...interface{})
- func PrintWarning(format string, args ...interface{})
- func PrintWarningf(format string, args ...interface{})
- func WarnOnError(err error, format string, args ...interface{})
- func Wrap(err error, format string, args ...interface{}) error
- func WrapContainer(containerName, action string, err error) error
- func WrapService(service string, err error) error
- type ConfigError
- type ContainerError
- type ServiceError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound indicates a resource was not found ErrNotFound = errors.New("not found") // ErrAlreadyExists indicates a resource already exists ErrAlreadyExists = errors.New("already exists") // ErrInvalidConfig indicates invalid configuration ErrInvalidConfig = errors.New("invalid configuration") ErrDockerUnavailable = errors.New("docker is not available") // ErrNotInitialized indicates Doku has not been initialized ErrNotInitialized = errors.New("doku is not initialized") // ErrPermissionDenied indicates insufficient permissions ErrPermissionDenied = errors.New("permission denied") // ErrTimeout indicates an operation timed out ErrTimeout = errors.New("operation timed out") // ErrUserCancelled indicates the user cancelled an operation ErrUserCancelled = errors.New("operation cancelled by user") )
Common error types that can be used throughout the application
Functions ¶
func IsAlreadyExists ¶
IsAlreadyExists checks if an error indicates something already exists
func IsNotFound ¶
IsNotFound checks if an error indicates something was not found
func IsPermissionDenied ¶
IsPermissionDenied checks if an error is a permission error
func LogOnError ¶
LogOnError logs an error if err is not nil (non-fatal)
func Must ¶
func Must(err error)
Must panics if err is not nil. Use sparingly and only for programmer errors.
func PrintError ¶
func PrintError(format string, args ...interface{})
PrintError prints an error message in red
func PrintErrorf ¶
func PrintErrorf(format string, args ...interface{})
PrintErrorf prints a formatted error message in red
func PrintWarning ¶
func PrintWarning(format string, args ...interface{})
PrintWarning prints a warning message in yellow
func PrintWarningf ¶
func PrintWarningf(format string, args ...interface{})
PrintWarningf prints a formatted warning message in yellow
func WarnOnError ¶
WarnOnError prints a warning if err is not nil
func WrapContainer ¶
WrapContainer wraps an error with container context
func WrapService ¶
WrapService wraps an error with service context
Types ¶
type ConfigError ¶
ConfigError represents a configuration error
func NewConfigError ¶
func NewConfigError(field, message string, err error) *ConfigError
NewConfigError creates a new ConfigError
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
func (*ConfigError) Unwrap ¶
func (e *ConfigError) Unwrap() error
type ContainerError ¶
ContainerError represents an error related to a Docker container
func NewContainerError ¶
func NewContainerError(containerName, action string, err error) *ContainerError
NewContainerError creates a new ContainerError
func (*ContainerError) Error ¶
func (e *ContainerError) Error() string
func (*ContainerError) Unwrap ¶
func (e *ContainerError) Unwrap() error
type ServiceError ¶
ServiceError represents an error related to a specific service
func NewServiceError ¶
func NewServiceError(service string, err error) *ServiceError
NewServiceError creates a new ServiceError
func (*ServiceError) Error ¶
func (e *ServiceError) Error() string
func (*ServiceError) Unwrap ¶
func (e *ServiceError) Unwrap() error
type ValidationError ¶
type ValidationError struct {
Errors []string
}
ValidationError represents a validation error with multiple issues
func NewValidationError ¶
func NewValidationError() *ValidationError
NewValidationError creates a new ValidationError
func (*ValidationError) Add ¶
func (e *ValidationError) Add(msg string)
Add adds a validation error message
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) HasErrors ¶
func (e *ValidationError) HasErrors() bool
HasErrors returns true if there are validation errors