Skip to content

Commit 20fae7b

Browse files
authored
Unify error messages formatting (#51)
1 parent 47c5600 commit 20fae7b

File tree

15 files changed

+38
-38
lines changed

15 files changed

+38
-38
lines changed

cert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ func GetCertFromEnvVariables(env []string) (*x509.Certificate, error) {
1818
p, _ := pem.Decode(pemEncoded)
1919

2020
if p == nil {
21-
return nil, errors.New("Missing certificate data")
21+
return nil, errors.New("missing certificate data")
2222
}
2323

2424
cert, err := x509.ParseCertificate(p.Bytes)
2525
if err != nil {
26-
return nil, fmt.Errorf("Certificate is invalid: %s", err)
26+
return nil, fmt.Errorf("certificate is invalid: %s", err)
2727
}
2828
return cert, nil
2929
}
3030
}
31-
return nil, errors.New("Missing certificate")
31+
return nil, errors.New("missing certificate")
3232
}

cert_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ func TestIfReturnsErrorWhenNoValidCertificateFound(t *testing.T) {
1313
err string
1414
env []string
1515
}{
16-
{"Missing certificate", nil},
17-
{"Missing certificate", []string{
16+
{"missing certificate", nil},
17+
{"missing certificate", []string{
1818
"ALLEGRO_PKI_SENSITIVE_VAR=xxx",
1919
"NOT_SENSITIVE=xxx",
2020
}},
21-
{"Missing certificate data", []string{
21+
{"missing certificate data", []string{
2222
"ALLEGRO_PKI_SENSITIVE_VAR=xxx",
2323
"CERTIFICATE=xxx",
2424
"NOT_SENSITIVE=xxx",

cmd/executor/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func initSentry(config executor.Config) error {
4949

5050
environment, err := runenv.Environment()
5151
if err != nil {
52-
return fmt.Errorf("Unable to determine runtime environment: %s", err)
52+
return fmt.Errorf("unable to determine runtime environment: %s", err)
5353
}
5454

5555
if environment == runenv.LocalEnv {
@@ -60,7 +60,7 @@ func initSentry(config executor.Config) error {
6060

6161
client, err := raven.New(config.SentryDSN)
6262
if err != nil {
63-
return fmt.Errorf("Unable to setup raven client: %s", err)
63+
return fmt.Errorf("unable to setup raven client: %s", err)
6464
}
6565
client.SetRelease(Version)
6666
client.SetEnvironment(string(environment))
@@ -71,7 +71,7 @@ func initSentry(config executor.Config) error {
7171
log.ErrorLevel,
7272
})
7373
if err != nil {
74-
return fmt.Errorf("Unable to setup sentry hook for logger: %s", err)
74+
return fmt.Errorf("unable to setup sentry hook for logger: %s", err)
7575
}
7676
sentryHook.Timeout = time.Second
7777
log.AddHook(sentryHook)

executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (e *Executor) createOptionsForLogstashServiceLogScrapping(taskInfo mesos.Ta
415415
func (e *Executor) checkCert(cert *x509.Certificate) error {
416416
certDuration := e.clock.Until(cert.NotAfter) - e.random.Duration(e.config.RandomExpirationRange)
417417
if certDuration <= 0 {
418-
return fmt.Errorf("Certificate valid period <= 0. Certificate invalid after %s", cert.NotAfter)
418+
return fmt.Errorf("certificate valid period <= 0 - certificate invalid after %s", cert.NotAfter)
419419
}
420420

421421
log.WithField("CertificateExpireDate", cert.NotAfter).Infof(

executor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestIfLaunchesCommandAndSendsStateUpdatesWhenTaskRequireCertButNoCertIsGive
5858
mock.AnythingOfType("mesos.TaskID"),
5959
mesos.TASK_FAILED,
6060
mock.MatchedBy(func(info state.OptionalInfo) bool {
61-
return "Cannot launch task: problem with certificate: Missing certificate" == *info.Message
61+
return "Cannot launch task: problem with certificate: missing certificate" == *info.Message
6262
})).Once()
6363

6464
exec := new(Executor)
@@ -303,7 +303,7 @@ func TestCertificateCheckReturnErrorIfKillWillBeScheduledInThePast(t *testing.T)
303303

304304
err := exec.checkCert(fakeCert)
305305

306-
assert.EqualError(t, err, "Certificate valid period <= 0. Certificate invalid after 0001-01-01 00:00:00 +0000 UTC")
306+
assert.EqualError(t, err, "certificate valid period <= 0 - certificate invalid after 0001-01-01 00:00:00 +0000 UTC")
307307
random.AssertExpectations(t)
308308
clock.AssertExpectations(t)
309309
}

health_checker.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ func newHealthCheck(check mesos.HealthCheck) healthCheckFunction {
100100
return func() error { return tcpHealthCheck(check) }
101101
}
102102

103-
return func() error { return fmt.Errorf("Unknown health check type: %s", check.GetType()) }
103+
return func() error { return fmt.Errorf("unknown health check type: %s", check.GetType()) }
104104
}
105105

106106
func commandHealthCheck(checkDefinition mesos.HealthCheck) error {
107107
if checkDefinition.GetCommand() == nil {
108-
return errors.New("Command health check not defined")
108+
return errors.New("command health check not defined")
109109
}
110110

111111
timeout := mesosutils.Duration(checkDefinition.GetTimeoutSeconds())
@@ -144,9 +144,9 @@ func commandHealthCheck(checkDefinition mesos.HealthCheck) error {
144144
if err := cmd.Run(); err != nil {
145145
if ctx.Err() == context.DeadlineExceeded {
146146
log.WithError(ctx.Err()).Info("Command health check timed out")
147-
return fmt.Errorf("Command health check timed out after %s", timeout)
147+
return fmt.Errorf("command health check timed out after %s", timeout)
148148
}
149-
return fmt.Errorf("Command health check errored: %s", err)
149+
return fmt.Errorf("command health check errored: %s", err)
150150
}
151151
return nil
152152
}
@@ -183,7 +183,7 @@ func httpHealthCheck(checkDefinition mesos.HealthCheck) error {
183183

184184
response, err := client.Get(checkURL.String())
185185
if err != nil {
186-
return fmt.Errorf("Health check error: %s", err)
186+
return fmt.Errorf("health check error: %s", err)
187187
}
188188
defer func() {
189189
if err := response.Body.Close(); err != nil {
@@ -194,7 +194,7 @@ func httpHealthCheck(checkDefinition mesos.HealthCheck) error {
194194
// Default executors treat return codes between 200 and 399 as success
195195
// See: https://github.com/apache/mesos/blob/1.1.3/include/mesos/mesos.proto#L355-L357
196196
if response.StatusCode < 200 || response.StatusCode >= 400 {
197-
return fmt.Errorf("Health check error: received status code %d, but expected codes between 200 and 399", response.StatusCode)
197+
return fmt.Errorf("health check error: received status code %d, but expected codes between 200 and 399", response.StatusCode)
198198
}
199199

200200
return nil

health_checker_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,30 @@ func TestNewHealthCheckShouldReturnNilWhenCheckPasses(t *testing.T) {
144144
func TestNewHealthCheckShouldReturnErrorOnUnknownCheck(t *testing.T) {
145145
healthCheck := newHealthCheck(mesos.HealthCheck{})
146146
err := healthCheck()
147-
assert.EqualError(t, err, "Unknown health check type: UNKNOWN")
147+
assert.EqualError(t, err, "unknown health check type: UNKNOWN")
148148
}
149149

150150
func TestNewHealthCheckShouldReturnErrorOnUdefinedCommand(t *testing.T) {
151151
commandType := mesos.HealthCheck_COMMAND
152152
healthCheck := newHealthCheck(mesos.HealthCheck{Type: &commandType})
153153
err := healthCheck()
154-
assert.EqualError(t, err, "Unknown health check type: COMMAND")
154+
assert.EqualError(t, err, "unknown health check type: COMMAND")
155155
}
156156

157157
func TestCommandHealthCheckShouldReturnErrorOnEmptyCheck(t *testing.T) {
158158
commandType := mesos.HealthCheck_COMMAND
159159
check := mesos.HealthCheck{Type: &commandType}
160160

161161
err := commandHealthCheck(check)
162-
assert.EqualError(t, err, "Command health check not defined")
162+
assert.EqualError(t, err, "command health check not defined")
163163
}
164164

165165
func TestCommandHealthCheckShouldReturnErrorOnInvalidCommand(t *testing.T) {
166166
invalidCommand := "false"
167167
command := mesos.CommandInfo{Value: &invalidCommand}
168168
check := mesos.HealthCheck{Command: &command}
169169
err := commandHealthCheck(check)
170-
assert.EqualError(t, err, "Command health check errored: exit status 1")
170+
assert.EqualError(t, err, "command health check errored: exit status 1")
171171
}
172172

173173
func TestCommandHealthCheckShouldReturnErrorOnInvalidCheck(t *testing.T) {
@@ -193,7 +193,7 @@ func TestCommandHealthCheckShouldReturnErrorOnInvalidCommandForNonShell(t *testi
193193
check := mesos.HealthCheck{Type: &commandType, Command: &command}
194194

195195
err := commandHealthCheck(check)
196-
assert.EqualError(t, err, "Command health check errored: exec: \"(true)\": executable file not found in $PATH")
196+
assert.EqualError(t, err, "command health check errored: exec: \"(true)\": executable file not found in $PATH")
197197
}
198198

199199
func TestCommandHealthCheckShouldReturnErrorOnAfterTimeout(t *testing.T) {
@@ -203,7 +203,7 @@ func TestCommandHealthCheckShouldReturnErrorOnAfterTimeout(t *testing.T) {
203203
timeout := 0.0
204204
check := mesos.HealthCheck{Command: &command, TimeoutSeconds: &timeout}
205205
err := commandHealthCheck(check)
206-
assert.EqualError(t, err, "Command health check timed out after 0s")
206+
assert.EqualError(t, err, "command health check timed out after 0s")
207207
}
208208

209209
func TestIfTCPHealthCheckPassesWhenPortIsOpen(t *testing.T) {
@@ -278,7 +278,7 @@ func TestIfHTTPHealthCheckFailsWhenRequestIsInvalid(t *testing.T) {
278278

279279
err := httpHealthCheck(check)
280280

281-
assert.EqualError(t, err, "Health check error: received status code 400, but expected codes between 200 and 399")
281+
assert.EqualError(t, err, "health check error: received status code 400, but expected codes between 200 and 399")
282282
}
283283

284284
func TestIfHTTPHealthCheckFailsWhenServiceIsUnavailable(t *testing.T) {
@@ -290,7 +290,7 @@ func TestIfHTTPHealthCheckFailsWhenServiceIsUnavailable(t *testing.T) {
290290

291291
err := httpHealthCheck(check)
292292

293-
assert.EqualError(t, err, "Health check error: received status code 503, but expected codes between 200 and 399")
293+
assert.EqualError(t, err, "health check error: received status code 503, but expected codes between 200 and 399")
294294
}
295295

296296
func TestIfHTTPHealthCheckFailsWhenNoServiceIsListeningOnConfiguredPort(t *testing.T) {

hook/vaas/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (c *defaultClient) FindDirectorID(name string) (int, error) {
138138
}
139139
}
140140

141-
return 0, fmt.Errorf("No Director with name %s found", name)
141+
return 0, fmt.Errorf("no Director with name %s found", name)
142142
}
143143

144144
// AddBackend adds backend in VaaS director.
@@ -202,7 +202,7 @@ func (c *defaultClient) GetDC(name string) (*DC, error) {
202202
}
203203
}
204204

205-
return nil, fmt.Errorf("No DC with name %s found", name)
205+
return nil, fmt.Errorf("no DC with name %s found", name)
206206
}
207207

208208
func (c *defaultClient) TaskStatus(task *Task) error {

hook/vaas/hook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (sh *Hook) RegisterBackend(taskInfo mesosutils.TaskInfo) error {
112112
if taskInfo.GetLabelValue(vaasAsyncLabelKey) == "true" {
113113
taskURI, err := sh.client.AddBackend(backend, true)
114114
if err != nil {
115-
return fmt.Errorf("Could not register with VaaS director: %s", err)
115+
return fmt.Errorf("could not register with VaaS director: %s", err)
116116
}
117117
log.Info("Waiting for successful Varnish configuration change...")
118118
sh.backendID = backend.ID
@@ -123,7 +123,7 @@ func (sh *Hook) RegisterBackend(taskInfo mesosutils.TaskInfo) error {
123123
}
124124
err = sh.watchTaskStatus(task)
125125
if err != nil {
126-
return fmt.Errorf("Could not register with VaaS director: %s", err)
126+
return fmt.Errorf("could not register with VaaS director: %s", err)
127127
}
128128
} else {
129129
_, err := sh.client.AddBackend(backend, false)
@@ -187,7 +187,7 @@ func (sh *Hook) watchTaskStatus(task *Task) (err error) {
187187

188188
switch task.Status {
189189
case StatusFailure:
190-
return fmt.Errorf("Registration in VaaS failed: %s", err)
190+
return fmt.Errorf("registration in VaaS failed: %s", err)
191191
case StatusSuccess:
192192
log.Info("Registered backend in VaaS")
193193
return nil

mesosutils/taskinfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (h TaskInfo) GetWeight() (int, error) {
111111
return strconv.Atoi(strings.TrimPrefix(tags, weightPrefix))
112112
}
113113
}
114-
return 0, fmt.Errorf("No weight defined")
114+
return 0, fmt.Errorf("no weight defined")
115115
}
116116

117117
// GetPorts returns a list of task ports

0 commit comments

Comments
 (0)