feat: Implement error handling framework (Task 4)
- Add AppError with error codes and hints system - Implement ConnectionError for SSH-specific errors - Add HandleSSHError for intelligent SSH error parsing - Add FormatConnectionError for user-friendly output - All 5 test functions passing (TestAppError, TestConnectionError, TestHandleSSHError, TestHandleSSHErrorNil, TestFormatConnectionError) - Update PROJECT_STATE.md to reflect Task 4 completion Progress: Tasks 1-4 complete (~30%)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user