errors

package
v0.0.0-...-4c93248 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Discovery Errors (2300-2309)
	DiskDiscoveryFailed   = 2300 + iota // Failed to discover disks
	DiskDiscoveryTimeout                // Discovery operation timed out
	DiskCorrelationFailed               // Failed to correlate disk paths
	DiskCacheError                      // Disk cache operation error
	DiskNotFound                        // Disk not found
	DiskAlreadyExists                   // Disk already exists in inventory

	// Topology Errors (2310-2319)
	DiskTopologyParseFailed = 2310 + iota // Failed to parse disk topology
	DiskTopologyFailed                    // Topology discovery failed
	DiskEnclosureNotFound                 // Enclosure not found
	DiskControllerNotFound                // Controller not found
	DiskTopologyInvalid                   // Invalid topology data
	DiskRAIDDetected                      // RAID controller detected (warning)

	// Health Monitoring Errors (2320-2329)
	DiskHealthCheckFailed  = 2320 + iota // Health check failed
	DiskSMARTReadFailed                  // Failed to read SMART attributes
	DiskSMARTNotAvailable                // SMART not available on device
	DiskSMARTRefreshFailed               // Failed to refresh SMART data
	DiskSMARTParseFailed                 // Failed to parse SMART data
	DiskNVMeHealthFailed                 // Failed to read NVMe health
	DiskIOStatFailed                     // Failed to get iostat metrics
	DiskHealthEvalFailed                 // Health evaluation failed
	DiskThresholdExceeded                // Health threshold exceeded

	// Probe Errors (2330-2349)
	DiskProbeScheduleFailed       = 2330 + iota // Failed to schedule probe
	DiskProbeStartFailed                        // Failed to start probe
	DiskProbeParseFailed                        // Failed to parse probe results
	DiskProbeTimeout                            // Probe operation timed out
	DiskProbeNotFound                           // Probe not found
	DiskProbeAlreadyRunning                     // Probe already running on device
	DiskProbeCancelled                          // Probe cancelled by user
	DiskProbeFailed                             // Probe execution failed
	DiskProbeConflict                           // Probe conflict detected
	DiskProbeConcurrencyLimit                   // Max concurrent probes reached
	DiskProbeNotRunning                         // Probe is not running
	DiskProbeNotSupported                       // SMART self-tests not supported on device
	DiskProbeScheduleNotFound                   // Probe schedule not found
	DiskProbeScheduleCreateFailed               // Failed to create probe schedule
	DiskProbeScheduleUpdateFailed               // Failed to update probe schedule
	DiskProbeScheduleDeleteFailed               // Failed to delete probe schedule

	// Hotplug Errors (2350-2359)
	DiskHotplugMonitorFailed  = 2350 + iota // Hotplug monitor failed
	DiskHotplugEventFailed                  // Failed to process hotplug event
	DiskUdevError                           // udev operation error
	DiskReconciliationFailed                // Reconciliation failed
	DiskStateTransitionFailed               // State transition failed

	// Naming Strategy Errors (2360-2369)
	DiskNamingStrategyInvalid = 2360 + iota // Invalid naming strategy
	DiskVdevConfGenFailed                   // vdev_id.conf generation failed
	DiskNameResolutionFailed                // Name resolution failed
	DiskDevicePathInvalid                   // Invalid device path

	// Configuration Errors (2370-2379)
	DiskConfigInvalid          = 2370 + iota // Invalid disk manager configuration
	DiskConfigValidationFailed               // Configuration validation failed
	DiskConfigLoadFailed                     // Failed to load configuration
	DiskConfigSaveFailed                     // Failed to save configuration
	DiskConfigCronInvalid                    // Invalid cron expression

	// State Management Errors (2380-2389)
	DiskStateLoadFailed      = 2380 + iota // Failed to load state file
	DiskStateSaveFailed                    // Failed to save state file
	DiskStateCorrupted                     // State file corrupted
	DiskStateMigrationFailed               // State migration failed
	DiskOperationNotFound                  // Operation not found

	// Tool Errors (2390-2399)
	DiskToolNotFound          = 2390 + iota // Required tool not found
	DiskToolVersionMismatch                 // Tool version mismatch
	DiskToolExecutionFailed                 // Tool execution failed
	DiskToolOutputParseFailed               // Failed to parse tool output
	DiskToolTimeout                         // Tool execution timed out
)

Disk Management Error Codes (2300-2399)

View Source
const (
	// General networking errors (1900-1919)
	NetworkOperationFailed          = 1900 + iota // Generic network operation failed
	NetworkPermissionDenied                       // Permission denied for network operation
	NetworkConfigurationInvalid                   // Invalid network configuration
	NetworkInterfaceNotFound                      // Network interface not found
	NetworkInterfaceOperationFailed               // Network interface operation failed
	NetworkAddressInvalid                         // Invalid network address
	NetworkRouteOperationFailed                   // Network route operation failed
	NetworkRouteNotFound                          // Network route not found
	NetworkDNSConfigurationFailed                 // DNS configuration failed
	NetworkValidationFailed                       // Network configuration validation failed
	NetworkStateInconsistent                      // Network state is inconsistent
	NetworkResourceBusy                           // Network resource is busy
	NetworkTimeout                                // Network operation timed out
	NetworkConnectivityFailed                     // Network connectivity test failed
	NetworkFeatureUnsupported                     // Network feature not supported
	NetworkPolicyViolation                        // Network policy violation
	NetworkBackendError                           // Network backend error
)

Network error codes (1900-1999)

View Source
const (
	// Netplan-specific errors (1920-1949)
	NetplanCommandFailed       = 1920 + iota // Netplan command failed
	NetplanCommandNotFound                   // Netplan command not found
	NetplanConfigInvalid                     // Invalid Netplan configuration
	NetplanApplyFailed                       // Netplan apply failed
	NetplanGenerateFailed                    // Netplan generate failed
	NetplanTryFailed                         // Netplan try failed
	NetplanGetFailed                         // Netplan get failed
	NetplanSetFailed                         // Netplan set failed
	NetplanStatusFailed                      // Netplan status failed
	NetplanVersionUnsupported                // Netplan version not supported
	NetplanYAMLParseError                    // Netplan YAML parsing error
	NetplanYAMLValidationError               // Netplan YAML validation error
	NetplanRendererInvalid                   // Invalid Netplan renderer
	NetplanFileOperationFailed               // Netplan file operation failed
	NetplanBackupFailed                      // Netplan backup operation failed
	NetplanRestoreFailed                     // Netplan restore operation failed
	NetplanDiffFailed                        // Netplan diff operation failed
	NetplanConfigFileNotFound                // Netplan config file not found
	NetplanConfigFileLocked                  // Netplan config file locked
	NetplanRollbackFailed                    // Netplan rollback failed
	NetplanTryTimeout                        // Netplan try timeout
	NetplanTryCancelled                      // Netplan try cancelled
)
View Source
const (
	// IP command errors (1950-1979)
	IPCommandFailed             = 1950 + iota // IP command failed
	IPLinkOperationFailed                     // IP link operation failed
	IPAddressOperationFailed                  // IP address operation failed
	IPRouteOperationFailed                    // IP route operation failed
	IPRuleOperationFailed                     // IP rule operation failed
	IPNeighborOperationFailed                 // IP neighbor operation failed
	IPTunnelOperationFailed                   // IP tunnel operation failed
	IPNamespaceOperationFailed                // IP namespace operation failed
	IPJSONParseError                          // IP command JSON parsing error
	IPInterfaceStateError                     // IP interface state error
	IPBridgeOperationFailed                   // IP bridge operation failed
	IPVLANOperationFailed                     // IP VLAN operation failed
	IPBondOperationFailed                     // IP bond operation failed
	IPMTUOperationFailed                      // IP MTU operation failed
	IPMACAddressOperationFailed               // IP MAC address operation failed
)
View Source
const (
	// Network validation errors (1980-1999)
	NetworkIPAddressInvalid     = 1980 + iota // Invalid IP address format
	NetworkCIDRInvalid                        // Invalid CIDR notation
	NetworkMACAddressInvalid                  // Invalid MAC address format
	NetworkPortInvalid                        // Invalid port number
	NetworkHostnameInvalid                    // Invalid hostname format
	NetworkVLANIDInvalid                      // Invalid VLAN ID
	NetworkMTUInvalid                         // Invalid MTU value
	NetworkGatewayInvalid                     // Invalid gateway address
	NetworkDNSServerInvalid                   // Invalid DNS server address
	NetworkSearchDomainInvalid                // Invalid search domain
	NetworkInterfaceNameInvalid               // Invalid interface name
	NetworkBondModeInvalid                    // Invalid bond mode
	NetworkBridgeConfigInvalid                // Invalid bridge configuration
	NetworkTunnelConfigInvalid                // Invalid tunnel configuration
	NetworkRoutingTableInvalid                // Invalid routing table
	NetworkMetricInvalid                      // Invalid route metric
	NetworkPrefixLengthInvalid                // Invalid prefix length
	NetworkProtocolInvalid                    // Invalid network protocol
	NetworkScopeInvalid                       // Invalid route scope
	NetworkTypeInvalid                        // Invalid network type
	NetworkBondConfigInvalid                  // Invalid bond configuration
)
View Source
const (
	// System Information Errors (2100-2119)
	SystemInfoCollectionFailed = 2100 + iota // Failed to collect system information
	SystemInfoParseError                     // Failed to parse system information
	SystemInfoInvalidData                    // Invalid system information data
	SystemInfoUnavailable                    // System information unavailable

	// Hostname Management Errors (2120-2129)
	SystemHostnameInvalid   = 2120 + iota // Invalid hostname format
	SystemHostnameSetFailed               // Failed to set hostname
	SystemHostnameGetFailed               // Failed to get hostname
	SystemHostnameTooLong                 // Hostname too long
	SystemHostnameReserved                // Hostname is reserved

	// User Management Errors (2130-2149)
	SystemUserNotFound              = 2130 + iota // User not found
	SystemUserAlreadyExists                       // User already exists
	SystemUserCreateFailed                        // Failed to create user
	SystemUserDeleteFailed                        // Failed to delete user
	SystemUserModifyFailed                        // Failed to modify user
	SystemUserInvalidName                         // Invalid username
	SystemUserInvalidPassword                     // Invalid password
	SystemUserInvalidShell                        // Invalid shell
	SystemUserInvalidHome                         // Invalid home directory
	SystemUserProtected                           // Protected user cannot be modified
	SystemUserPasswordEncryptFailed               // Failed to encrypt password

	// Group Management Errors (2150-2169)
	SystemGroupNotFound         = 2150 + iota // Group not found
	SystemGroupAlreadyExists                  // Group already exists
	SystemGroupCreateFailed                   // Failed to create group
	SystemGroupDeleteFailed                   // Failed to delete group
	SystemGroupModifyFailed                   // Failed to modify group
	SystemGroupInvalidName                    // Invalid group name
	SystemGroupProtected                      // Protected group cannot be modified
	SystemGroupMembershipFailed               // Failed to modify group membership

	// Power Management Errors (2170-2189)
	SystemPowerShutdownFailed  = 2170 + iota // Failed to shutdown system
	SystemPowerRebootFailed                  // Failed to reboot system
	SystemPowerScheduleFailed                // Failed to schedule power operation
	SystemPowerCancelFailed                  // Failed to cancel scheduled operation
	SystemPowerInvalidDelay                  // Invalid power operation delay
	SystemPowerStatusFailed                  // Failed to get power status
	SystemPowerOperationDenied               // Power operation denied
	SystemPowerInvalidMessage                // Invalid power operation message

	// System Configuration Errors (2190-2199)
	SystemTimezoneInvalid        = 2190 + iota // Invalid timezone
	SystemTimezoneSetFailed                    // Failed to set timezone
	SystemLocaleInvalid                        // Invalid locale
	SystemLocaleSetFailed                      // Failed to set locale
	SystemConfigValidationFailed               // System configuration validation failed
	SystemHealthCheckFailed                    // System health check failed
	SystemOperationNotSupported                // System operation not supported
	SystemResourceUnavailable                  // System resource unavailable
	SystemPermissionInsufficient               // Insufficient system permissions
)

System Management Error Codes (2100-2199)

View Source
const (
	// Configuration Errors (1000-1099)
	ConfigNotFound           = 1000 + iota // Config file not found
	ConfigInvalid                          // Invalid config format
	ConfigLoadFailed                       // Failed to load config
	ConfigWriteFailed                      // Failed to write config
	ConfigPermissionDenied                 // Permission denied accessing config
	ConfigDirectoryError                   // Config directory error
	ConfigValidationFailed                 // Config validation failed
	ConfigMarshalFailed                    // Config serialization failed
	ConfigUnmarshalFailed                  // Config deserialization failed
	ConfigHomeDirectoryError               // Error getting home directory
	ConfigReadError                        // Error reading config
	ConfigWriteError                       // Error writing config
	ConfigParseError                       // Error parsing config
)

Error code ranges: 1000-1099: Configuration errors 1100-1199: Server errors 1200-1299: Active Directory errors 1300-1399: Command execution 1400-1499: Health check 1500-1599: Lifecycle management 1600-1699: Rodent errors 1700-1799: Shares + ACL errors 2000-2999: ZFS operations Domain-specific error code ranges:

View Source
const (
	// Server Errors (1100-1199)
	ServerStart             = 1100 + iota // Failed to start server
	ServerShutdown                        // Error during shutdown
	ServerBind                            // Failed to bind port
	ServerTimeout                         // Operation timeout
	ServerMiddleware                      // Middleware error
	ServerRouting                         // Routing error
	ServerRequestValidation               // Request validation failed
	ServerResponseError                   // Response generation error
	ServerContextCancelled                // Context cancelled
	ServerTLSError                        // TLS configuration error
	ServerInternalError
	ServerBadRequest // Bad request error
)
View Source
const (
	// Active Directory Errors (1200-1299)
	ADConnectFailed      = 1200 + iota // Failed to connect to AD
	ADSearchFailed                     // Failed to search AD
	ADUserNotFound                     // User not found
	ADGroupNotFound                    // Group not found
	ADPermissionDenied                 // Permission denied
	ADInvalidCredentials               // Invalid credentials
	ADInvalidFilter                    // Invalid search filter
	ADInvalidBaseDN                    // Invalid base DN
	ADInvalidAttribute                 // Invalid attribute
	ADInvalidGroup                     // Invalid group
	ADInvalidUser                      // Invalid user
	ADInvalidPassword                  // Invalid password (policy violation)

	ADCreateUserFailed     // Failed to add user
	ADUpdateUserFailed     // Failed to update user
	ADDeleteUserFailed     // Failed to delete user
	ADCreateGroupFailed    // Failed to add group
	ADUpdateGroupFailed    // Failed to update group
	ADDeleteGroupFailed    // Failed to delete group
	ADCreateComputerFailed // Failed to add computer
	ADUpdateComputerFailed // Failed to update computer
	ADDeleteComputerFailed // Failed to delete computer
	ADEncodePasswordFailed // Failed to encode password
	ADSetPasswordFailed    // Failed to set password
	ADEnableAccountFailed  // Failed to enable account
	ADCreateOUFailed       // Failed to create OU
)
View Source
const (
	// TODO: Remove redundant error codes
	// ZFS Operations (2000-2999)
	ZFSCommandFailed    = 2000 + iota // ZFS command execution failed
	ZFSPoolNotFound                   // Pool not found
	ZFSPermissionDenied               // Permission denied
	ZFSPropertyError                  // Property operation failed
	SchedulerError                    // Scheduler error
	ZFSPropertyValueTooLong
	ZFSInvalidPropertyValue
	ZFSMountError // Mount operation failed
	ZFSInvalidMountPoint
	ZFSRestrictedMountPoint
	ZFSCloneError // Clone operation failed
	ZFSQuotaError // Quota operation failed
	ZFSIOError    // I/O error during operation
	ZFSInvalidSize
	ZFSQuotaExceeded
	ZFSQuotaInvalid
	ZFSPermissionError
	ZFSRequestValidationError

	ZFSNameLeadingSlash
	ZFSNameEmptyComponent
	ZFSNameTrailingSlash
	ZFSNameInvalidChar
	ZFSNameMultipleDelimiters // multiple '@'/'#' delimiters found
	ZFSNameNoLetter           // pool doesn't begin with a letter
	ZFSNameReserved
	ZFSNameDiskLike
	ZFSNameTooLong
	ZFSNameSelfRef   // "."
	ZFSNameParentRef // ".."
	ZFSNameNoAtSign  // Missing "@" in snapshot
	ZFSNameNoPound   // Missing "#" in bookmark
	ZFSNameInvalid

	ZFSDatasetNotFound // Dataset not found
	ZFSDatasetCreate
	ZFSDatasetList
	ZFSDatasetDestroy
	ZFSDatasetGetProperty
	ZFSDatasetSetProperty
	ZFSDatasetPropertyNotFound
	ZFSDatasetClone
	ZFSDatasetInvalidName
	ZFSDatasetInvalidProperty
	ZFSDatasetRename
	ZFSDatasetSnapshot
	ZFSDatasetOperation

	ZFSDatasetSend
	ZFSDatasetReceive
	ZFSDatasetNoReceiveToken

	// Transfer management errors
	TransferNotFound
	TransferInvalidState
	TransferPauseFailed
	TransferStopFailed
	TransferResumeFailed

	// Transfer policy errors
	TransferPolicyNotFound
	TransferPolicyAlreadyExists
	TransferPolicyInvalidConfig
	TransferPolicySnapshotPolicyNotFound
	TransferPolicySnapshotPolicyInUse
	TransferPolicyNoSnapshots
	TransferPolicyTransferRunning
	TransferPolicySchedulerError
	TransferPolicyInvalidState

	ZFSSnapshotList
	ZFSSnapshotDestroy
	ZFSSnapshotRollback
	ZFSSnapshotFailed // Snapshot operation failed
	ZFSSnapshotInvalidName
	ZFSSnapshotInvalidProperty
	ZFSSnapshotPolicyError // Auto-snapshot policy operation failed

	ZFSBookmarkFailed
	ZFSBookmarkInvalidName
	ZFSBookmarkInvalidProperty

	ZFSClonePromoteFailed
	ZFSMountOperationFailed
	ZFSUnmountOperationFailed
	ZFSPoolScrubFailed
	ZFSPoolResilverFailed

	ZFSVolumeOperationFailed

	ZFSPoolCreate
	ZFSPoolImport
	ZFSPoolExport
	ZFSPoolStatus
	ZFSPoolList
	ZFSPoolDestroy
	ZFSPoolGetProperty
	ZFSPoolSetProperty
	ZFSPoolPropertyNotFound
	ZFSPoolInvalidName
	ZFSPoolInvalidDevice
	ZFSPoolDeviceOperation
	ZFSPoolTooManyDevices
	ZFSPoolRestrictedDevice
)
View Source
const (
	// Command Execution (1300-1399)
	CommandNotFound     = 1300 + iota // Command not found
	CommandExecution                  // Execution failed
	CommandTimeout                    // Command timed out
	CommandPermission                 // Permission denied
	CommandInvalidInput               // Invalid command input
	CommandOutputParse                // Output parsing failed
	CommandSignal                     // Signal handling failed
	CommandContext                    // Context handling error
	CommandPipe                       // Command pipe error
	CommandWorkDir                    // Working directory error
)
View Source
const (
	// Health Check (1400-1499)
	HealthCheckFailed     = 1400 + iota // Health check failed
	HealthCheckTimeout                  // Health check timed out
	HealthCheckComponent                // Component check failed
	HealthCheckConfig                   // Health check config error
	HealthCheckEndpoint                 // Endpoint error
	HealthCheckClient                   // Client error
	HealthCheckValidation               // Validation error
	HealthCheckThreshold                // Threshold exceeded
	HealthCheckState                    // State transition error
	HealthCheckRecovery                 // Recovery failed
)
View Source
const (
	// Lifecycle Management (1500-1599)
	LifecyclePID      = 1500 + iota // PID file operation failed
	LifecycleShutdown               // Shutdown process error
	LifecycleSignal                 // Signal handling error
	LifecycleReload                 // Config reload failed
	LifecycleHook                   // Lifecycle hook error
	LifecycleState                  // State transition error
	LifecycleLock                   // Lock acquisition failed
	LifecycleCleanup                // Cleanup operation failed
	LifecycleDaemon                 // Daemon operation failed
	LifecycleResource               // Resource management error
)
View Source
const (
	// Rodent Errors (1600-1699)
	RodentMisc = 1600 + iota // Miscellaneous program error
	FSError
	NotFoundError // Not found error
	LoggerError   // Logger error
)
View Source
const (
	// Shares + ACL Errors (1700-1799)
	// ACL errors
	FACLInvalidInput = 1700 + iota // Invalid ACL input
	FACLReadError
	FACLWriteError
	FACLParseError
	FACLPathNotFound
	FACLInvalidPrincipal
	FACLUnsupportedFS

	// Shares service errors
	SharesInvalidInput    // Invalid share input or parameters
	SharesOperationFailed // Generic share operation failure
	SharesNotFound        // Share not found
	SharesAlreadyExists   // Share already exists
	SharesServiceFailed   // Share service operation failed
	SharesInternalError   // Internal shares subsystem error
	SharesAccessDenied    // Access denied for share operation
	SharesPathInvalid     // Invalid path for share
	SharesConfigInvalid   // Invalid share configuration
	SharesNetworkError    // Network error during share operation
	SharesLimitExceeded   // Exceeded share limits
	SharesProtocolError   // Protocol-specific share error
)
View Source
const (
	// System Errors (1750-1799)
	OperationFailed  = 1750 + iota // Generic operation failed
	PermissionDenied               // Permission denied

	// SSH Key Errors (1800-1849)
	SSHKeyPairGenerationFailed     = 1800 + iota // Failed to generate SSH key pair
	SSHKeyPairWriteFailed                        // Failed to write SSH key pair
	SSHKeyPairReadFailed                         // Failed to read SSH key pair
	SSHKeyPairDeleteFailed                       // Failed to delete SSH key pair
	SSHKeyPairNotFound                           // SSH key pair not found
	SSHKeyPairAlreadyExists                      // SSH key pair already exists
	SSHKeyPairInvalidType                        // Invalid SSH key type
	SSHKeyPairInvalidPeeringID                   // Invalid peering ID
	SSHKeyPairInvalidPublicKey                   // Invalid public key format
	SSHKeyPairInvalidHostname                    // Invalid hostname/IP
	SSHKeyPairPermissionDenied                   // Permission denied for SSH key operation
	SSHKnownHostAddFailed                        // Failed to add to known hosts
	SSHKnownHostRemoveFailed                     // Failed to remove from known hosts
	SSHKnownHostEntryNotFound                    // Known host entry not found
	SSHKnownHostEntryAlreadyExists               // Known host entry already exists
)
View Source
const (
	// Service Errors (1850-1899)
	ServiceNotFound      = 1850 + iota // Service not found
	ServiceUpdateFailed                // Service update failed
	ServiceStartFailed                 // Service start failed
	ServiceStopFailed                  // Service stop failed
	ServiceRestartFailed               // Service restart failed
	ServiceStatusFailed                // Service status check failed
)

Variables

View Source
var (
	ErrZFSPoolPropertyNotFound = &RodentError{
		Code:       ZFSPoolPropertyNotFound,
		Domain:     DomainZFS,
		Message:    errorDefinitions[ZFSPoolPropertyNotFound].message,
		HTTPStatus: errorDefinitions[ZFSPoolPropertyNotFound].httpStatus,
	}

	ErrZFSDatasetPropertyNotFound = &RodentError{
		Code:       ZFSDatasetPropertyNotFound,
		Domain:     DomainZFS,
		Message:    errorDefinitions[ZFSDatasetPropertyNotFound].message,
		HTTPStatus: errorDefinitions[ZFSDatasetPropertyNotFound].httpStatus,
	}
)

Create sentinel errors for common cases

Functions

func ErrorResponse

func ErrorResponse(requestID string, err error) *proto.CommandResponse

ErrorResponse creates a CommandResponse with error information from a RodentError This is a simpler version without additional payload data

func ErrorResponseWithPayload

func ErrorResponseWithPayload(requestID string, err error, payload []byte) *proto.CommandResponse

ErrorResponseWithPayload creates a CommandResponse with error information from a RodentError

func GetHTTPStatus

func GetHTTPStatus(err error) int

func Is

func Is(err, target error) bool

Is checks if an error matches a sentinel error

func IsRodentError

func IsRodentError(err error) bool

IsRodentError checks if an error is a RodentError

func SuccessResponse

func SuccessResponse(requestID string, message string, payload []byte) *proto.CommandResponse

SuccessResponse creates a CommandResponse indicating success

Types

type CommandError

type CommandError struct {
	Command  string
	ExitCode int
	StdErr   string
}

CommandError helper for command execution errors

type Domain

type Domain string

Domain represents the subsystem where the error originated

const (
	DomainConfig    Domain = "CONFIG"
	DomainServer    Domain = "SERVER"
	DomainZFS       Domain = "ZFS"
	DomainCommand   Domain = "CMD"
	DomainHealth    Domain = "HEALTH"
	DomainLifecycle Domain = "LIFECYCLE"
	DomainAD        Domain = "AD"
	DomainShares    Domain = "SHARES"
	DomainSSH       Domain = "SSH"
	DomainMisc      Domain = "MISC"
	DomainSystem    Domain = "SYSTEM"
	DomainService   Domain = "SERVICE"
)
const (
	DomainNetwork Domain = "NETWORK"
)

type ErrorCode

type ErrorCode int

ErrorCode represents unique error identifiers

func GetCode

func GetCode(err error) (ErrorCode, bool)

GetCode extracts the error code from an error if it's a RodentError If not a RodentError, returns 0 and false

type RodentError

type RodentError struct {
	Code    ErrorCode `json:"code"`
	Domain  Domain    `json:"domain"`
	Message string    `json:"message"`
	Details string    `json:"details,omitempty"`
	// Context    string           `json:"context,omitempty"`
	HTTPStatus int `json:"-"`

	// The Metadata field is designed for additional contextual information
	// that doesn't fit into the standard error fields but is valuable for
	// debugging and API responses. It's particularly useful for:
	// - API responses where JSON serialization includes the metadata
	// - Logging with structured details
	// - Debugging with command-specific information
	// - Error tracking/monitoring systems
	// TODO: perhaps use a map[string]interface{} for flexibility?
	// TODO: Consider map[string][]string for multiple values to accommodate error chains?
	Metadata map[string]string `json:"metadata,omitempty"`
}

func FromProto

func FromProto(protoErr *proto.RodentError) *RodentError

FromProto creates a RodentError from a proto.RodentError

func GetErrorWithCode

func GetErrorWithCode(err error, code ErrorCode) *RodentError

GetErrorWithCode returns the first RodentError in the error chain with the specified code Returns nil if no matching error is found

func New

func New(code ErrorCode, details string) *RodentError

New creates a new RodentError

func NewCommandError

func NewCommandError(cmd string, exitCode int, stderr string) *RodentError

func Wrap

func Wrap(err error, code ErrorCode) *RodentError

Wrap wraps an existing error with additional context

func (*RodentError) Error

func (e *RodentError) Error() string

func (*RodentError) Is

func (e *RodentError) Is(target error) bool

Is implements the interface for errors.Is

func (*RodentError) MarshalJSON

func (e *RodentError) MarshalJSON() ([]byte, error)

MarshalJSON customizes JSON serialization

func (*RodentError) ToProto

func (e *RodentError) ToProto() *proto.RodentError

ToProto converts a RodentError to a proto.RodentError for gRPC responses

func (*RodentError) Unwrap

func (e *RodentError) Unwrap() error

Unwrap implements the interface for errors.Unwrap

func (*RodentError) WithMetadata

func (e *RodentError) WithMetadata(key, value string) *RodentError

Jump to

Keyboard shortcuts

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