- Added lock file exclusions for pnpm in .gitignore. - Removed obsolete package-lock.json from the api and portal directories. - Enhanced Cloudflare adapter with additional interfaces for zones and tunnels. - Improved Proxmox adapter error handling and logging for API requests. - Updated Proxmox VM parameters with validation rules in the API schema. - Enhanced documentation for Proxmox VM specifications and examples.
120 lines
3.2 KiB
Go
120 lines
3.2 KiB
Go
package virtualmachine
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// ErrorCategory represents a categorized error with appropriate condition type and reason
|
|
type ErrorCategory struct {
|
|
Type string
|
|
Reason string
|
|
}
|
|
|
|
// categorizeError categorizes errors into appropriate types for better handling
|
|
func categorizeError(errorStr string) ErrorCategory {
|
|
errorStr = strings.ToLower(errorStr)
|
|
|
|
// API not implemented errors
|
|
if strings.Contains(errorStr, "501") ||
|
|
strings.Contains(errorStr, "not implemented") ||
|
|
strings.Contains(errorStr, "importdisk") {
|
|
return ErrorCategory{
|
|
Type: "APINotSupported",
|
|
Reason: "ImportDiskAPINotImplemented",
|
|
}
|
|
}
|
|
|
|
// Configuration errors (non-retryable without manual intervention)
|
|
if strings.Contains(errorStr, "cannot get provider config") ||
|
|
strings.Contains(errorStr, "cannot get credentials") ||
|
|
strings.Contains(errorStr, "cannot find site") ||
|
|
strings.Contains(errorStr, "cannot create proxmox client") {
|
|
return ErrorCategory{
|
|
Type: "ConfigurationError",
|
|
Reason: "InvalidConfiguration",
|
|
}
|
|
}
|
|
|
|
// Quota errors
|
|
if strings.Contains(errorStr, "quota") ||
|
|
strings.Contains(errorStr, "exceeded") {
|
|
return ErrorCategory{
|
|
Type: "QuotaExceeded",
|
|
Reason: "ResourceQuotaExceeded",
|
|
}
|
|
}
|
|
|
|
// Node health errors
|
|
if strings.Contains(errorStr, "node") &&
|
|
(strings.Contains(errorStr, "unhealthy") ||
|
|
strings.Contains(errorStr, "not reachable") ||
|
|
strings.Contains(errorStr, "offline")) {
|
|
return ErrorCategory{
|
|
Type: "NodeUnhealthy",
|
|
Reason: "NodeHealthCheckFailed",
|
|
}
|
|
}
|
|
|
|
// Image/Storage errors
|
|
if strings.Contains(errorStr, "image") &&
|
|
(strings.Contains(errorStr, "not found") ||
|
|
strings.Contains(errorStr, "cannot find")) {
|
|
return ErrorCategory{
|
|
Type: "ImageNotFound",
|
|
Reason: "ImageNotFoundInStorage",
|
|
}
|
|
}
|
|
|
|
// Lock file errors
|
|
if strings.Contains(errorStr, "lock") ||
|
|
strings.Contains(errorStr, "timeout") {
|
|
return ErrorCategory{
|
|
Type: "LockError",
|
|
Reason: "LockFileTimeout",
|
|
}
|
|
}
|
|
|
|
// Authentication errors (non-retryable without credential fix)
|
|
if strings.Contains(errorStr, "authentication") ||
|
|
strings.Contains(errorStr, "unauthorized") ||
|
|
strings.Contains(errorStr, "401") ||
|
|
strings.Contains(errorStr, "invalid credentials") ||
|
|
strings.Contains(errorStr, "forbidden") ||
|
|
strings.Contains(errorStr, "403") {
|
|
return ErrorCategory{
|
|
Type: "AuthenticationError",
|
|
Reason: "AuthenticationFailed",
|
|
}
|
|
}
|
|
|
|
// Network/Connection errors (retryable)
|
|
if strings.Contains(errorStr, "network") ||
|
|
strings.Contains(errorStr, "connection") ||
|
|
strings.Contains(errorStr, "timeout") ||
|
|
strings.Contains(errorStr, "502") ||
|
|
strings.Contains(errorStr, "503") ||
|
|
strings.Contains(errorStr, "connection refused") ||
|
|
strings.Contains(errorStr, "connection reset") {
|
|
return ErrorCategory{
|
|
Type: "NetworkError",
|
|
Reason: "TransientNetworkFailure",
|
|
}
|
|
}
|
|
|
|
// Generic creation failure
|
|
if strings.Contains(errorStr, "cannot create vm") ||
|
|
strings.Contains(errorStr, "failed to create") {
|
|
return ErrorCategory{
|
|
Type: "CreationFailed",
|
|
Reason: "VMCreationFailed",
|
|
}
|
|
}
|
|
|
|
// Default: generic failure
|
|
return ErrorCategory{
|
|
Type: "Failed",
|
|
Reason: "UnknownError",
|
|
}
|
|
}
|
|
|