-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
errors.go
165 lines (142 loc) · 8.29 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
157
158
159
160
161
162
163
164
165
package keygen
import (
"errors"
"fmt"
"time"
)
// ErrorCode defines various error codes that are handled explicitly.
type ErrorCode string
const (
ErrorCodeEnvironmentInvalid ErrorCode = "ENVIRONMENT_INVALID"
ErrorCodeEnvironmentNotSupported ErrorCode = "ENVIRONMENT_NOT_SUPPORTED"
ErrorCodeTokenFormatInvalid ErrorCode = "TOKEN_FORMAT_INVALID"
ErrorCodeTokenInvalid ErrorCode = "TOKEN_INVALID"
ErrorCodeTokenExpired ErrorCode = "TOKEN_EXPIRED"
ErrorCodeTokenNotAllowed ErrorCode = "TOKEN_NOT_ALLOWED"
ErrorCodeLicenseInvalid ErrorCode = "LICENSE_INVALID"
ErrorCodeLicenseExpired ErrorCode = "LICENSE_EXPIRED"
ErrorCodeLicenseSuspended ErrorCode = "LICENSE_SUSPENDED"
ErrorCodeLicenseNotAllowed ErrorCode = "LICENSE_NOT_ALLOWED"
ErrorCodeFingerprintTaken ErrorCode = "FINGERPRINT_TAKEN"
ErrorCodeMachineLimitExceeded ErrorCode = "MACHINE_LIMIT_EXCEEDED"
ErrorCodeProcessLimitExceeded ErrorCode = "MACHINE_PROCESS_LIMIT_EXCEEDED"
ErrorCodeComponentFingerprintConflict ErrorCode = "COMPONENTS_FINGERPRINT_CONFLICT"
ErrorCodeComponentFingerprintTaken ErrorCode = "COMPONENTS_FINGERPRINT_TAKEN"
ErrorCodeMachineHeartbeatDead ErrorCode = "MACHINE_HEARTBEAT_DEAD"
ErrorCodeProcessHeartbeatDead ErrorCode = "PROCESS_HEARTBEAT_DEAD"
ErrorCodeNotFound ErrorCode = "NOT_FOUND"
)
// Error represents an API error response.
type Error struct {
Response *Response
Title string
Detail string
Code string
Source string
}
func (e *Error) Error() string {
res := e.Response
return fmt.Sprintf("an error occurred: id=%s status=%d size=%d body=%s", res.ID, res.Status, res.Size, res.tldr())
}
// EnvironmentError represents an API environment error due to an invalid environment.
type EnvironmentError struct{ Err *Error }
func (e *EnvironmentError) Error() string { return "environment is invalid" }
func (e *EnvironmentError) Unwrap() error { return e.Err }
// LicenseTokenError represents an API authentication error due to an invalid license token.
type LicenseTokenError struct{ Err *Error }
func (e *LicenseTokenError) Error() string { return "license token is invalid" }
func (e *LicenseTokenError) Unwrap() error { return e.Err }
// LicenseKeyError represents an API authentication error due to an invalid license key.
type LicenseKeyError struct{ Err *Error }
func (e *LicenseKeyError) Error() string { return "license key is invalid" }
func (e *LicenseKeyError) Unwrap() error { return e.Err }
// NotAuthorizedError represents an API permission error.
type NotAuthorizedError struct{ Err *Error }
func (e *NotAuthorizedError) Error() string { return "not authorized to perform the request" }
func (e *NotAuthorizedError) Unwrap() error { return e.Err }
// NotFoundError represents an API not found error.
type NotFoundError struct{ Err *Error }
func (e *NotFoundError) Error() string { return "resource was not found" }
func (e *NotFoundError) Unwrap() error { return e.Err }
// LicenseFileError represents an invalid license file error.
type LicenseFileError struct{ Err error }
func (e *LicenseFileError) Error() string { return "license file is invalid" }
func (e *LicenseFileError) Unwrap() error { return e.Err }
// MachineFileError represents an invalid machine file error.
type MachineFileError struct{ Err error }
func (e *MachineFileError) Error() string { return "machine file is invalid" }
func (e *MachineFileError) Unwrap() error { return e.Err }
// RateLimitError represents an API rate limiting error.
type RateLimitError struct {
Window string
Count int
Limit int
Remaining int
Reset time.Time
RetryAfter int
Err error
}
func (e *RateLimitError) Error() string { return "rate limit has been exceeded" }
func (e *RateLimitError) Unwrap() error { return e.Err }
// General errors
var (
ErrReleaseLocationMissing = errors.New("release has no download URL")
ErrUpgradeNotAvailable = errors.New("no upgrades available (already up-to-date)")
ErrResponseSignatureMissing = errors.New("response signature is missing")
ErrResponseSignatureInvalid = errors.New("response signature is invalid")
ErrResponseDigestMissing = errors.New("response digest is missing")
ErrResponseDigestInvalid = errors.New("response digest is invalid")
ErrResponseDateMissing = errors.New("response date is missing")
ErrResponseDateInvalid = errors.New("response date is invalid")
ErrResponseDateTooOld = errors.New("response date is too old")
ErrRequestSignatureMissing = errors.New("request signature is missing")
ErrRequestSignatureInvalid = errors.New("request signature is invalid")
ErrRequestDigestMissing = errors.New("request digest is missing")
ErrRequestDigestInvalid = errors.New("request digest is invalid")
ErrRequestDateMissing = errors.New("request date is missing")
ErrRequestDateInvalid = errors.New("request date is invalid")
ErrRequestDateTooOld = errors.New("request date is too old")
ErrPublicKeyMissing = errors.New("public key is missing")
ErrPublicKeyInvalid = errors.New("public key is invalid")
ErrValidationFingerprintMissing = errors.New("validation fingerprint scope is missing")
ErrValidationComponentsMissing = errors.New("validation components scope is missing")
ErrValidationProductMissing = errors.New("validation product scope is missing")
ErrHeartbeatPingFailed = errors.New("heartbeat ping failed")
ErrHeartbeatRequired = errors.New("heartbeat is required")
ErrHeartbeatDead = errors.New("heartbeat is dead")
ErrMachineAlreadyActivated = errors.New("machine is already activated")
ErrMachineLimitExceeded = errors.New("machine limit has been exceeded")
ErrMachineNotFound = errors.New("machine no longer exists")
ErrProcessNotFound = errors.New("process no longer exists")
ErrMachineFileNotSupported = errors.New("machine file is not supported")
ErrMachineFileNotEncrypted = errors.New("machine file is not encrypted")
ErrMachineFileNotGenuine = errors.New("machine file is not genuine")
ErrMachineFileExpired = errors.New("machine file is expired")
ErrComponentNotActivated = errors.New("component is not activated")
ErrComponentAlreadyActivated = errors.New("component is already activated")
ErrComponentConflict = errors.New("component is duplicated")
ErrProcessLimitExceeded = errors.New("process limit has been exceeded")
ErrLicenseSchemeNotSupported = errors.New("license scheme is not supported")
ErrLicenseSchemeMissing = errors.New("license scheme is missing")
ErrLicenseKeyMissing = errors.New("license key is missing")
ErrLicenseKeyNotGenuine = errors.New("license key is not genuine")
ErrLicenseNotActivated = errors.New("license is not activated")
ErrLicenseNotAllowed = errors.New("license authentication is not allowed by policy")
ErrLicenseExpired = errors.New("license is expired")
ErrLicenseSuspended = errors.New("license is suspended")
ErrLicenseTooManyMachines = errors.New("license has too many machines")
ErrLicenseTooManyCores = errors.New("license has too many cores")
ErrLicenseTooManyProcesses = errors.New("license has too many processes")
ErrLicenseNotSigned = errors.New("license is not signed")
ErrLicenseInvalid = errors.New("license is invalid")
ErrLicenseFileNotSupported = errors.New("license file is not supported")
ErrLicenseFileNotEncrypted = errors.New("license file is not encrypted")
ErrLicenseFileNotGenuine = errors.New("license file is not genuine")
ErrLicenseFileExpired = errors.New("license file is expired")
ErrLicenseFileSecretMissing = errors.New("license file secret is missing")
ErrTokenNotAllowed = errors.New("token authentication is not allowed by policy")
ErrTokenFormatInvalid = errors.New("token format is invalid")
ErrTokenInvalid = errors.New("token is invalid")
ErrTokenExpired = errors.New("token is expired")
ErrSystemClockUnsynced = errors.New("system clock is out of sync")
)