errors

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Is     = errors.Is
	As     = errors.As
	Unwrap = errors.Unwrap
)

Basic error check functions from standard library

Functions

func GetErrorMessage

func GetErrorMessage(code ErrorCode) string

GetErrorMessage returns the message for a given error code

func IsNVMLSuccess

func IsNVMLSuccess(err error) bool

IsNVMLSuccess checks if the error is a "SUCCESS" message from NVML

Types

type Error

type Error interface {
	error
	Code() ErrorCode
	WithMessage(msg string) Error
	WithData(data any) Error
	GetData() any
	Unwrap() error
}

Error represents a domain-specific error with context

type ErrorCode

type ErrorCode string

ErrorCode represents a unique identifier for each error type

const (
	// System errors
	ErrInternal        ErrorCode = "internal_error"
	ErrInvalidArgument ErrorCode = "invalid_argument"
	ErrNotImplemented  ErrorCode = "not_implemented"
	ErrUnavailable     ErrorCode = "service_unavailable"

	// Configuration errors
	ErrInvalidConfig   ErrorCode = "invalid_configuration"
	ErrMissingConfig   ErrorCode = "missing_configuration"
	ErrBindFlags       ErrorCode = "bind_flags_failed"
	ErrInvalidInterval ErrorCode = "invalid_interval"
	ErrLoadConfig      ErrorCode = "load_configuration"

	// Logging errors
	ErrInvalidLogLevel ErrorCode = "invalid_log_level"

	// Initialization errors
	ErrInitFailed     ErrorCode = "initialization_failed"
	ErrShutdownFailed ErrorCode = "shutdown_failed"

	// Resource errors
	ErrResourceBusy      ErrorCode = "resource_busy"
	ErrResourceNotFound  ErrorCode = "resource_not_found"
	ErrResourceExhausted ErrorCode = "resource_exhausted"

	// Application errors
	ErrInitApp         ErrorCode = "init_app_failed"
	ErrMainLoop        ErrorCode = "main_loop_failed"
	ErrSetGPUState     ErrorCode = "get_gpu_state_failed"
	ErrGetGPUState     ErrorCode = "get_gpu_state_failed"
	ErrShutdownGPU     ErrorCode = "shutdown_gpu_failed"
	ErrResetPowerLimit ErrorCode = "reset_power_limit_failed"
	ErrEnableAutoFan   ErrorCode = "enable_auto_fan_failed"

	// Operation errors
	ErrOperationFailed  ErrorCode = "operation_failed"
	ErrTimeout          ErrorCode = "operation_timeout"
	ErrInvalidOperation ErrorCode = "invalid_operation"

	// Metrics errors
	ErrInitMetrics    ErrorCode = "init_metrics_failed"
	ErrCollectMetrics ErrorCode = "collect_metrics_failed"
	ErrCloseMetrics   ErrorCode = "close_metrics_failed"
)

Common error codes

type Factory

type Factory interface {
	New(code ErrorCode) Error
	Wrap(code ErrorCode, err error) Error
	WithMessage(code ErrorCode, msg string) Error
	WithData(code ErrorCode, data any) Error
}

Factory defines methods for creating domain errors

func New

func New() Factory

New creates a Factory instance for error creation

Jump to

Keyboard shortcuts

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