-
Notifications
You must be signed in to change notification settings - Fork 69
/
errors.go
237 lines (202 loc) · 7.31 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package types
import (
"errors"
"fmt"
"regexp"
"strings"
)
var (
// ErrInterrupt represents a context cancellation.
ErrInterrupt = errors.New("operation canceled")
maxTaskPathNesting = 5
ErrConnectionStringFormat = "there was an error connecting to New Relic platform. This is an indication that your firewall or proxy settings do not allow outbound traffic to the New Relic platform. To configure the use of an HTTP proxy, use the HTTP_PROXY and/or HTTPS_PROXY environment variables. For more details visit https://github.com/newrelic/newrelic-cli/blob/main/docs/GETTING_STARTED.md#using-an-http-proxy. Details: %s"
ErrValidation = errors.New("there was a failure locating the data that was posted to New Relic. Please try again later or contact New Relic support. For real-time platform status info visit https://status.newrelic.com/")
ErrDiscovery = errors.New("failed to detect your system's hostname. Please contact New Relic support")
ErrPostEvent = errors.New("there was a failure posting data to New Relic. Please try again later or contact New Relic support. For real-time platform status info visit https://status.newrelic.com/")
ErrLicenseKey = errors.New("the configured license key is invalid for the configured account. Please set a valid license key with the `newrelic profile` command. For more details visit https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key")
)
type EventType string
var EventTypes = struct {
InstallStarted EventType
AccountIDMissing EventType
APIKeyMissing EventType
RegionMissing EventType
UnableToConnect EventType
UnableToFetchLicenseKey EventType
LicenseKeyFetchedOk EventType
UnableToOverrideClient EventType
UnableToPostData EventType
InstallCompleted EventType
InstallCancelled EventType
InvalidIngestKey EventType
UnableToDiscover EventType
NrIntegrationPollingErrror EventType
OtherError EventType
UnableToLocatePostedData EventType
InvalidUserAPIKeyFormat EventType
InvalidRegion EventType
}{
InstallStarted: "InstallStarted",
AccountIDMissing: "AccountIDMissing",
APIKeyMissing: "APIKeyMissing",
RegionMissing: "RegionMissing",
UnableToConnect: "UnableToConnect",
UnableToFetchLicenseKey: "UnableToFetchLicenseKey",
LicenseKeyFetchedOk: "LicenseKeyFetchedOk",
UnableToPostData: "UnableToPostData",
UnableToLocatePostedData: "UnableToLocatePostedData",
InstallCompleted: "InstallCompleted",
InstallCancelled: "InstallCancelled",
UnableToOverrideClient: "UnableToOverrideClient",
InvalidIngestKey: "InvalidIngestKey",
UnableToDiscover: "UnableToDiscover",
NrIntegrationPollingErrror: "NrIntegrationPollingErrror",
OtherError: "OtherError",
InvalidUserAPIKeyFormat: "InvalidUserAPIKeyFormat",
InvalidRegion: "InvalidRegion",
}
func TryParseEventType(e string) (EventType, bool) {
switch e {
case "InstallStarted":
return EventTypes.InstallStarted, true
case "AccountIDMissing":
return EventTypes.AccountIDMissing, true
case "APIKeyMissing":
return EventTypes.APIKeyMissing, true
case "RegionMissing":
return EventTypes.RegionMissing, true
case "UnableToConnect":
return EventTypes.UnableToConnect, true
case "UnableToFetchLicenseKey":
return EventTypes.UnableToFetchLicenseKey, true
case "LicenseKeyFetchedOk":
return EventTypes.LicenseKeyFetchedOk, true
case "UnableToPostData":
return EventTypes.UnableToPostData, true
case "InstallCompleted":
return EventTypes.InstallCompleted, true
case "UnableToOverrideClient":
return EventTypes.UnableToOverrideClient, true
case "InvalidIngestKey":
return EventTypes.InvalidIngestKey, true
case "UnableToDiscover":
return EventTypes.UnableToDiscover, true
case "NrIntegrationPollingErrror":
return EventTypes.NrIntegrationPollingErrror, true
case "InvalidUserAPIKeyFormat":
return EventTypes.InvalidUserAPIKeyFormat, true
case "InvalidRegion":
return EventTypes.InvalidRegion, true
}
return "", false
}
type GoTaskError interface {
error
TaskPath() []string
SetError(msg string)
}
// GoTaskError represents a task failure reported by go-task.
type GoTaskGeneralError struct {
error
taskPath []string
}
func (e GoTaskGeneralError) Error() string {
return e.error.Error()
}
func (e GoTaskGeneralError) SetError(msg string) {
//nolint:staticcheck
e.error = errors.New(msg)
}
func (e GoTaskGeneralError) TaskPath() []string {
return e.taskPath
}
func NewGoTaskGeneralError(err error) GoTaskError {
pattern := `task: Failed to run task \"(.+?)\": `
str := strings.Repeat("(?:%[1]s)?", maxTaskPathNesting)
re := regexp.MustCompile(fmt.Sprintf(str, pattern))
parsed := re.FindStringSubmatch(err.Error())
taskPath := []string{}
for i, p := range parsed {
if i == 0 {
continue
}
if p != "" {
taskPath = append(taskPath, p)
}
}
stripped := re.ReplaceAllString(err.Error(), "")
return GoTaskGeneralError{
taskPath: taskPath,
error: errors.New(stripped),
}
}
// ErrNonZeroExitCode represents a non-zero exit code error reported by go-task.
type ErrNonZeroExitCode struct {
GoTaskError
additionalContext string
}
func NewNonZeroExitCode(originalError GoTaskError, additionalContext string) ErrNonZeroExitCode {
return ErrNonZeroExitCode{
GoTaskError: originalError,
additionalContext: additionalContext,
}
}
func (e ErrNonZeroExitCode) Error() string {
if e.additionalContext != "" {
return fmt.Sprintf("%s: %s", e.GoTaskError.Error(), e.additionalContext)
}
return e.GoTaskError.Error()
}
type UnsupportedOperatingSystemError struct {
Err error
}
func (e *UnsupportedOperatingSystemError) Error() string {
return e.Err.Error()
}
// UpdateRequiredError represents when a user is using an older version
// of the CLI and is required to update when running the `newrelic install` command.
type UpdateRequiredError struct {
Err error
Details string
}
func (e *UpdateRequiredError) Error() string {
return e.Err.Error()
}
type UncaughtError struct {
Err error
}
func (e *UncaughtError) Error() string {
return e.Err.Error()
}
// nolint: golint
var ErrorFetchingLicenseKey = errors.New("Oops, we're having some difficulties fetching your license key. Please try again later, or see our documentation for installing manually https://docs.newrelic.com/docs/using-new-relic/cross-product-functions/install-configure/install-new-relic")
type ErrUnalbeToFetchLicenseKey struct {
Err error
Details string
}
func (e *ErrUnalbeToFetchLicenseKey) Error() string {
return "could not fetch license key"
}
const PaymentRequiredExceptionMessage = `
Your account has exceeded its plan data limit.
Take full advantage of New Relic's platform by managing
your account's plan and payment options at the URL below.`
type ConnectionError struct {
Err error
}
func (p ConnectionError) Error() string {
return fmt.Sprintf("Connection Error: %s", p.Err)
}
type DetailError struct {
EventName EventType
Details string
}
func NewDetailError(eventName EventType, details string) *DetailError {
return &DetailError{
eventName,
details,
}
}
func (e *DetailError) Error() string {
return e.Details
}