-
Notifications
You must be signed in to change notification settings - Fork 13
/
errors.go
156 lines (133 loc) · 5.03 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package cloudops
import "fmt"
// Custom storage operation error codes.
const (
_ = iota + 5000
// ErrVolDetached is code for a volume is detached on the instance
ErrVolDetached
// ErrVolInval is the code for a invalid volume
ErrVolInval
// ErrVolAttachedOnRemoteNode is code when a volume is not attached locally
// but attached on a remote node
ErrVolAttachedOnRemoteNode
// ErrVolNotFound is code when a volume is not found
ErrVolNotFound
// ErrInvalidDevicePath is code when a volume/disk has invalid device path
ErrInvalidDevicePath
// ErrExponentialTimeout is code when all the retries with exponential backoff have exhausted
ErrExponentialTimeout
// ErrDiskGreaterOrEqualToExpandSize is code when a volume/disk expansion call fails
// as the given disk is already at a size greater than or equal to requested size
ErrDiskGreaterOrEqualToExpandSize
// ErrVolumeAttachedOnMultipleNodes is code when a volume is attached to multiple nodes
ErrVolumeAttachedOnMultipleNodes
)
// ErrNotFound is error type when an object of Type with ID is not found
type ErrNotFound struct {
// Type is the type of the object
Type string
// ID is the unique identifer of the object
ID string
}
func (e *ErrNotFound) Error() string {
return fmt.Sprintf("%s with ID %s was not found", e.Type, e.ID)
}
// ErrNotSupported is the error type for unsupported operations
type ErrNotSupported struct {
// Operation is the operation not being supported
Operation string
// Reason is an optional reason for not supporting the operation
Reason string
}
func (e *ErrNotSupported) Error() string {
errString := fmt.Sprintf("Operation: %s is not supported", e.Operation)
if len(e.Reason) > 0 {
errString = fmt.Sprintf("%s. Reason: %s", errString, e.Reason)
}
return errString
}
// StorageError error returned for storage operations
type StorageError struct {
// Code is one of storage operation driver error codes.
Code int
// Msg is human understandable error message.
Msg string
// Instance provides more information on the error.
Instance string
}
// NewStorageError creates a new custom storage error instance
func NewStorageError(code int, msg string, instance string) error {
return &StorageError{Code: code, Msg: msg, Instance: instance}
}
func (e *StorageError) Error() string {
return e.Msg
}
// ErrNoInstanceGroup is returned when instance doesn't belong to an instance group
type ErrNoInstanceGroup struct {
// Reason is an optional reason for not belong to an instance group
Reason string
}
func (e *ErrNoInstanceGroup) Error() string {
errString := "Instance doesn't belong to an instance group"
if len(e.Reason) > 0 {
errString = fmt.Sprintf("%s. Reason: %s", errString, e.Reason)
}
return errString
}
// ErrInvalidStoragePoolUpdateRequest is returned when an unsupported or invalid request
// is sent to get the updated storage config on an instance
type ErrInvalidStoragePoolUpdateRequest struct {
// Request is the request that caused the invalid error
Request *StoragePoolUpdateRequest
// Reason is the reason why the request was invalid
Reason string
}
func (e *ErrInvalidStoragePoolUpdateRequest) Error() string {
return fmt.Sprintf("Invalid request to update storage on instance due to: %s Request: %v",
e.Reason, e.Request)
}
// ErrCurrentCapacityHigherThanDesired is returned when the current capacity of the instance is already higher than
// the desired capacity
type ErrCurrentCapacityHigherThanDesired struct {
// Current is the current capacity
Current uint64
// Desired is the desired new capacity
Desired uint64
}
func (e *ErrCurrentCapacityHigherThanDesired) Error() string {
return fmt.Sprintf("current capacity (%d) is higher than desired capacity: %d", e.Current, e.Desired)
}
// ErrCloudProviderRequestFailure is returned when an unknown API request failure occurred.
type ErrCloudProviderRequestFailure struct {
// Request is the API function name
Request string
// Message is the error message returned by the cloud provider
Message string
}
func (e *ErrCloudProviderRequestFailure) Error() string {
return fmt.Sprintf("Request %s returns %s", e.Request, e.Message)
}
// ErrInvalidMaxDriveSizeRequest is returned when an unsupported or invalid request
// is sent to get the max drive size
type ErrInvalidMaxDriveSizeRequest struct {
// Request is the request that caused the invalid error
Request *MaxDriveSizeRequest
// Reason is the reason why the request was invalid
Reason string
}
func (e *ErrInvalidMaxDriveSizeRequest) Error() string {
return fmt.Sprintf("Invalid request to get the max drive size: %s Request: %v",
e.Reason, e.Request)
}
// ErrMaxDriveSizeCandidateNotFound is returned when an unsupported or invalid request
// is sent to get the max drive size
type ErrMaxDriveSizeCandidateNotFound struct {
// Request is the request that caused the error
Request *MaxDriveSizeRequest
// Reason is the reason why the request caused an error
Reason string
}
func (e *ErrMaxDriveSizeCandidateNotFound) Error() string {
return fmt.Sprintf("could not find a suitable max drive size candidate: %s Request: %v",
e.Reason, e.Request)
}