847989df75
- git mv cmd/ internal/ pkg/ test/ go.mod go.sum Makefile build.sh docs/ v1/ - Create v1/README.md with V1 documentation - Update root README for V1 + V2 structure - V1 still builds (cd v1 && go build ./cmd/hostkeeper) and 105 tests pass - Root is now clean for V2 development
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package errors
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// Error codes
|
|
const (
|
|
ErrHostNotFound = "HOST_NOT_FOUND"
|
|
ErrAuthFailed = "AUTH_FAILED"
|
|
ErrConnectionTimeout = "CONNECTION_TIMEOUT"
|
|
ErrInvalidConfig = "INVALID_CONFIG"
|
|
ErrKeyNotFound = "KEY_NOT_FOUND"
|
|
ErrPermissionDenied = "PERMISSION_DENIED"
|
|
ErrFileCorrupted = "FILE_CORRUPTED"
|
|
ErrInvalidCredentials = "INVALID_CREDENTIALS"
|
|
)
|
|
|
|
// AppError represents an application error with code, message, cause, and hints
|
|
type AppError struct {
|
|
Code string
|
|
Message string
|
|
Cause error
|
|
Hints []string
|
|
}
|
|
|
|
// Error implements the error interface
|
|
func (e *AppError) Error() string {
|
|
if e.Cause != nil {
|
|
return fmt.Sprintf("[%s] %s: %v", e.Code, e.Message, e.Cause)
|
|
}
|
|
return fmt.Sprintf("[%s] %s", e.Code, e.Message)
|
|
}
|
|
|
|
// Unwrap returns the underlying cause for use with errors.Is/errors.As
|
|
func (e *AppError) Unwrap() error {
|
|
return e.Cause
|
|
}
|
|
|
|
// NewAppError creates a new application error
|
|
func NewAppError(code, message string, cause error, hints []string) *AppError {
|
|
return &AppError{
|
|
Code: code,
|
|
Message: message,
|
|
Cause: cause,
|
|
Hints: hints,
|
|
}
|
|
} |