errors

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 indicates Docker is not available
	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 As

func As(err error, target interface{}) bool

As attempts to cast an error to a specific type

func Is

func Is(err, target error) bool

Is checks if an error is of a specific type

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists checks if an error indicates something already exists

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if an error indicates something was not found

func IsPermissionDenied

func IsPermissionDenied(err error) bool

IsPermissionDenied checks if an error is a permission error

func LogOnError

func LogOnError(err error, format string, args ...interface{})

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 MustValue

func MustValue[T any](value T, err error) T

MustValue returns the value or panics if err is not nil.

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

func WarnOnError(err error, format string, args ...interface{})

WarnOnError prints a warning if err is not nil

func Wrap

func Wrap(err error, format string, args ...interface{}) error

Wrap wraps an error with additional context

func WrapContainer

func WrapContainer(containerName, action string, err error) error

WrapContainer wraps an error with container context

func WrapService

func WrapService(service string, err error) error

WrapService wraps an error with service context

Types

type ConfigError

type ConfigError struct {
	Field   string
	Message string
	Err     error
}

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

type ContainerError struct {
	ContainerName string
	Action        string
	Err           error
}

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

type ServiceError struct {
	Service string
	Err     error
}

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

Jump to

Keyboard shortcuts

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