errors

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 2 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetErrorDetails

func GetErrorDetails(err error) map[string]interface{}

GetErrorDetails returns the details from an error, or nil if not a DodotError

func IsErrorCode

func IsErrorCode(err error, code ErrorCode) bool

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

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

func Wrapf

func Wrapf(err error, code ErrorCode, format string, args ...interface{}) *DodotError

Wrapf wraps an existing error with a formatted message

func (*DodotError) Error

func (e *DodotError) Error() string

Error implements the error interface

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"
	ErrRuleMatch       ErrorCode = "TRIGGER_MATCH"
	ErrTriggerExecute  ErrorCode = "TRIGGER_EXECUTE"

	// Handler errors
	ErrHandlerNotFound ErrorCode = "TRICK_NOT_FOUND"
	ErrHandlerInvalid  ErrorCode = "TRICK_INVALID"
	ErrHandlerExecute  ErrorCode = "TRICK_EXECUTE"

	// Operation errors
	ErrOperationInvalid  ErrorCode = "OPERATION_INVALID"
	ErrOperationConflict ErrorCode = "OPERATION_CONFLICT"
	ErrOperationExecute  ErrorCode = "OPERATION_EXECUTE"

	// 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

func GetErrorCode(err error) ErrorCode

GetErrorCode returns the error code from an error, or ErrUnknown if not a DodotError

Jump to

Keyboard shortcuts

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