Documentation
¶
Overview ¶
Package errors defines error types and codes for dodot. It provides structured errors with codes for stable testing and clear error messages for users.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetErrorDetails ¶
GetErrorDetails returns the details from an error, or nil if not a DodotError
func IsErrorCode ¶
IsErrorCode checks if an error has a specific error code
Types ¶
type DodotError ¶
type DodotError struct {
Code ErrorCode
Message string
Details map[string]interface{}
Wrapped error
}
DodotError represents a structured error with code and details
func New ¶
func New(code ErrorCode, message string) *DodotError
New creates a new DodotError with the given code and message
Example ¶
err := New(ErrNotFound, "configuration file not found").
WithDetail("path", "/etc/dodot/config.toml").
WithDetail("searchPaths", []string{"/etc/dodot", "~/.config/dodot"})
fmt.Println(err.Error())
Output: [NOT_FOUND] configuration file not found
func Newf ¶
func Newf(code ErrorCode, format string, args ...interface{}) *DodotError
Newf creates a new DodotError with a formatted message
func Wrap ¶
func Wrap(err error, code ErrorCode, message string) *DodotError
Wrap wraps an existing error with a DodotError
Example ¶
// Simulate a low-level error
fsErr := errors.New("permission denied")
// Wrap it with context
err := Wrap(fsErr, ErrFileAccess, "cannot read configuration").
WithDetail("path", "/etc/dodot/config.toml").
WithDetail("user", "dodot")
fmt.Println(err.Error())
Output: [FILE_ACCESS] cannot read configuration: permission denied
func Wrapf ¶
func Wrapf(err error, code ErrorCode, format string, args ...interface{}) *DodotError
Wrapf wraps an existing error with a formatted message
func (*DodotError) Is ¶
func (e *DodotError) Is(target error) bool
Is implements errors.Is interface
func (*DodotError) Unwrap ¶
func (e *DodotError) Unwrap() error
Unwrap implements the errors.Unwrap interface
func (*DodotError) WithDetail ¶
func (e *DodotError) WithDetail(key string, value interface{}) *DodotError
WithDetail adds a detail to the error
func (*DodotError) WithDetails ¶
func (e *DodotError) WithDetails(details map[string]interface{}) *DodotError
WithDetails adds multiple details to the error
type ErrorCode ¶
type ErrorCode string
ErrorCode represents a unique error code for stable testing
const ( // General errors ErrUnknown ErrorCode = "UNKNOWN" ErrInternal ErrorCode = "INTERNAL" ErrInvalidInput ErrorCode = "INVALID_INPUT" ErrNotFound ErrorCode = "NOT_FOUND" ErrAlreadyExists ErrorCode = "ALREADY_EXISTS" ErrPermission ErrorCode = "PERMISSION" ErrNotImplemented ErrorCode = "NOT_IMPLEMENTED" // Configuration errors ErrConfigLoad ErrorCode = "CONFIG_LOAD" ErrConfigParse ErrorCode = "CONFIG_PARSE" ErrConfigValid ErrorCode = "CONFIG_INVALID" ErrConfigRead ErrorCode = "CONFIG_READ" // Pack errors ErrPackNotFound ErrorCode = "PACK_NOT_FOUND" ErrPackInvalid ErrorCode = "PACK_INVALID" ErrPackAccess ErrorCode = "PACK_ACCESS" ErrPackSkipped ErrorCode = "PACK_SKIPPED" ErrPackEmpty ErrorCode = "PACK_EMPTY" ErrPackExists ErrorCode = "PACK_EXISTS" ErrPackInit ErrorCode = "PACK_INIT" // Trigger errors ErrTriggerNotFound ErrorCode = "TRIGGER_NOT_FOUND" ErrTriggerInvalid ErrorCode = "TRIGGER_INVALID" ErrTriggerMatch ErrorCode = "TRIGGER_MATCH" ErrTriggerExecute ErrorCode = "TRIGGER_EXECUTE" // PowerUp errors ErrPowerUpNotFound ErrorCode = "POWERUP_NOT_FOUND" ErrPowerUpInvalid ErrorCode = "POWERUP_INVALID" ErrPowerUpExecute ErrorCode = "POWERUP_EXECUTE" // Action errors ErrActionInvalid ErrorCode = "ACTION_INVALID" ErrActionConflict ErrorCode = "ACTION_CONFLICT" ErrActionExecute ErrorCode = "ACTION_EXECUTE" ErrActionCreate ErrorCode = "ACTION_CREATE" // FileSystem errors ErrFileNotFound ErrorCode = "FILE_NOT_FOUND" ErrFileAccess ErrorCode = "FILE_ACCESS" ErrFileCreate ErrorCode = "FILE_CREATE" ErrFileWrite ErrorCode = "FILE_WRITE" ErrSymlinkCreate ErrorCode = "SYMLINK_CREATE" ErrSymlinkExists ErrorCode = "SYMLINK_EXISTS" ErrDirCreate ErrorCode = "DIR_CREATE" // Status errors ErrStatusCheck ErrorCode = "STATUS_CHECK" )
Error codes for different error categories
func GetErrorCode ¶
GetErrorCode returns the error code from an error, or ErrUnknown if not a DodotError