Skip to content
This repository was archived by the owner on Feb 7, 2020. It is now read-only.

Commit a6dae85

Browse files
authored
Merge pull request #7 from ripienaar/err
(misc) remove not needed err.Error() calls
2 parents 76ba4fc + e460f06 commit a6dae85

File tree

8 files changed

+52
-52
lines changed

8 files changed

+52
-52
lines changed

protocol/v1/constructors.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewReply(request protocol.Request, certname string) (rep protocol.Reply, er
5050

5151
j, err := request.JSON()
5252
if err != nil {
53-
err = fmt.Errorf("Could not turn Request %s into a JSON document: %s", request.RequestID(), err.Error())
53+
err = fmt.Errorf("Could not turn Request %s into a JSON document: %s", request.RequestID(), err)
5454
return
5555
}
5656

@@ -73,13 +73,13 @@ func NewReplyFromSecureReply(sr protocol.SecureReply) (rep protocol.Reply, err e
7373

7474
err = r.IsValidJSON(sr.Message())
7575
if err != nil {
76-
err = fmt.Errorf("The JSON body from the SecureReply is not a valid Reply message: %s", err.Error())
76+
err = fmt.Errorf("The JSON body from the SecureReply is not a valid Reply message: %s", err)
7777
return
7878
}
7979

8080
err = json.Unmarshal([]byte(sr.Message()), r)
8181
if err != nil {
82-
err = fmt.Errorf("Could not parse JSON data from Secure Reply: %s", err.Error())
82+
err = fmt.Errorf("Could not parse JSON data from Secure Reply: %s", err)
8383
return
8484
}
8585

@@ -102,13 +102,13 @@ func NewRequestFromSecureRequest(sr protocol.SecureRequest) (req protocol.Reques
102102

103103
err = r.IsValidJSON(sr.Message())
104104
if err != nil {
105-
err = fmt.Errorf("The JSON body from the SecureRequest is not a valid Request message: %s", err.Error())
105+
err = fmt.Errorf("The JSON body from the SecureRequest is not a valid Request message: %s", err)
106106
return
107107
}
108108

109109
err = json.Unmarshal([]byte(sr.Message()), r)
110110
if err != nil {
111-
err = fmt.Errorf("Could not parse JSON data from Secure Request: %s", err.Error())
111+
err = fmt.Errorf("Could not parse JSON data from Secure Request: %s", err)
112112
return
113113
}
114114

@@ -125,7 +125,7 @@ func NewSecureReply(reply protocol.Reply) (secure protocol.SecureReply, err erro
125125

126126
err = secure.SetMessage(reply)
127127
if err != nil {
128-
err = fmt.Errorf("Could not set message on SecureReply structure: %s", err.Error())
128+
err = fmt.Errorf("Could not set message on SecureReply structure: %s", err)
129129
}
130130

131131
return
@@ -146,7 +146,7 @@ func NewSecureReplyFromTransport(message protocol.TransportMessage) (secure prot
146146

147147
err = secure.IsValidJSON(data)
148148
if err != nil {
149-
err = fmt.Errorf("The JSON body from the TransportMessage is not a valid SecureReply message: %s", err.Error())
149+
err = fmt.Errorf("The JSON body from the TransportMessage is not a valid SecureReply message: %s", err)
150150
return
151151
}
152152

@@ -169,7 +169,7 @@ func NewSecureRequest(request protocol.Request, publicCert string, privateCert s
169169
if protocol.IsSecure() {
170170
pubcerttxt, err = readFile(publicCert)
171171
if err != nil {
172-
err = fmt.Errorf("Could not read public certificate: %s", err.Error())
172+
err = fmt.Errorf("Could not read public certificate: %s", err)
173173
return
174174
}
175175
}
@@ -183,7 +183,7 @@ func NewSecureRequest(request protocol.Request, publicCert string, privateCert s
183183

184184
err = secure.SetMessage(request)
185185
if err != nil {
186-
err = fmt.Errorf("Could not set message SecureRequest structure: %s", err.Error())
186+
err = fmt.Errorf("Could not set message SecureRequest structure: %s", err)
187187
}
188188

189189
return
@@ -205,7 +205,7 @@ func NewSecureRequestFromTransport(message protocol.TransportMessage, caPath str
205205

206206
err = secure.IsValidJSON(data)
207207
if err != nil {
208-
err = fmt.Errorf("The JSON body from the TransportMessage is not a valid SecureRequest message: %s", err.Error())
208+
err = fmt.Errorf("The JSON body from the TransportMessage is not a valid SecureRequest message: %s", err)
209209
return
210210
}
211211

protocol/v1/reply.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ func (r *reply) Time() time.Time {
7878
func (r *reply) JSON() (body string, err error) {
7979
j, err := json.Marshal(r)
8080
if err != nil {
81-
err = fmt.Errorf("Could not JSON Marshal: %s", err.Error())
81+
err = fmt.Errorf("Could not JSON Marshal: %s", err)
8282
protocolErrorCtr.Inc()
8383
return
8484
}
8585

8686
body = string(j)
8787

8888
if err = r.IsValidJSON(body); err != nil {
89-
err = fmt.Errorf("JSON produced from the Reply does not pass validation: %s", err.Error())
89+
err = fmt.Errorf("JSON produced from the Reply does not pass validation: %s", err)
9090
return
9191
}
9292

@@ -102,7 +102,7 @@ func (r *reply) Version() string {
102102
func (r *reply) IsValidJSON(data string) (err error) {
103103
_, errors, err := schemas.Validate(schemas.ReplyV1, data)
104104
if err != nil {
105-
err = fmt.Errorf("Could not validate Reply JSON data: %s", err.Error())
105+
err = fmt.Errorf("Could not validate Reply JSON data: %s", err)
106106
return
107107
}
108108

protocol/v1/request.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,14 @@ func (r *request) JSON() (body string, err error) {
262262
j, err := json.Marshal(r)
263263
if err != nil {
264264
protocolErrorCtr.Inc()
265-
err = fmt.Errorf("Could not JSON Marshal: %s", err.Error())
265+
err = fmt.Errorf("Could not JSON Marshal: %s", err)
266266
return
267267
}
268268

269269
body = string(j)
270270

271271
if err = r.IsValidJSON(body); err != nil {
272-
err = fmt.Errorf("JSON produced from the Request does not pass validation: %s", err.Error())
272+
err = fmt.Errorf("JSON produced from the Request does not pass validation: %s", err)
273273
return
274274
}
275275

@@ -293,7 +293,7 @@ func (r *request) Version() string {
293293
func (r *request) IsValidJSON(data string) (err error) {
294294
_, errors, err := schemas.Validate(schemas.RequestV1, data)
295295
if err != nil {
296-
err = fmt.Errorf("Could not validate Request JSON data: %s", err.Error())
296+
err = fmt.Errorf("Could not validate Request JSON data: %s", err)
297297
return
298298
}
299299

protocol/v1/schema/gen.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func writeSchema(schema string, variable string, outfile *os.File) {
2222

2323
infile, err := ioutil.ReadFile(fname)
2424
if err != nil {
25-
log.Fatalf("Could not open %s: %s", fname, err.Error())
25+
log.Fatalf("Could not open %s: %s", fname, err)
2626
}
2727

2828
encoded := base64.StdEncoding.EncodeToString(infile)
@@ -41,13 +41,13 @@ func main() {
4141

4242
infile, err := os.Open(fname)
4343
if err != nil {
44-
log.Fatalf("Could not open %s: %s", fname, err.Error())
44+
log.Fatalf("Could not open %s: %s", fname, err)
4545
}
4646
defer infile.Close()
4747

4848
tmpfile, err := ioutil.TempFile("", "generate")
4949
if err != nil {
50-
log.Fatalf("Could not open tempfile: %s", err.Error())
50+
log.Fatalf("Could not open tempfile: %s", err)
5151
}
5252
defer os.Remove(tmpfile.Name())
5353

protocol/v1/schemas.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (s *jsonSchemas) Validate(schema []byte, data string) (result bool, errors
2727
if err != nil {
2828
badJsonCtr.Inc()
2929
protocolErrorCtr.Inc()
30-
err = fmt.Errorf("Could not validate incoming document: %s", err.Error())
30+
err = fmt.Errorf("Could not validate incoming document: %s", err)
3131
return
3232
}
3333

protocol/v1/security_reply.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (r *secureReply) SetMessage(reply protocol.Reply) (err error) {
2828
j, err := reply.JSON()
2929
if err != nil {
3030
protocolErrorCtr.Inc()
31-
err = fmt.Errorf("Could not JSON encode reply message to store it in the Secure Reply: %s", err.Error())
31+
err = fmt.Errorf("Could not JSON encode reply message to store it in the Secure Reply: %s", err)
3232
return
3333
}
3434

@@ -64,14 +64,14 @@ func (r *secureReply) JSON() (body string, err error) {
6464
j, err := json.Marshal(r)
6565
if err != nil {
6666
protocolErrorCtr.Inc()
67-
err = fmt.Errorf("Could not JSON Marshal: %s", err.Error())
67+
err = fmt.Errorf("Could not JSON Marshal: %s", err)
6868
return
6969
}
7070

7171
body = string(j)
7272

7373
if err = r.IsValidJSON(body); err != nil {
74-
err = fmt.Errorf("JSON produced from the SecureRequest does not pass validation: %s", err.Error())
74+
err = fmt.Errorf("JSON produced from the SecureRequest does not pass validation: %s", err)
7575
return
7676
}
7777

@@ -87,7 +87,7 @@ func (r *secureReply) Version() string {
8787
func (r *secureReply) IsValidJSON(data string) (err error) {
8888
_, errors, err := schemas.Validate(schemas.SecureReplyV1, data)
8989
if err != nil {
90-
err = fmt.Errorf("Could not validate SecureReply JSON data: %s", err.Error())
90+
err = fmt.Errorf("Could not validate SecureReply JSON data: %s", err)
9191
return
9292
}
9393

protocol/v1/security_request.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (r *secureRequest) SetMessage(request protocol.Request) (err error) {
4848
j, err := request.JSON()
4949
if err != nil {
5050
protocolErrorCtr.Inc()
51-
err = fmt.Errorf("Could not JSON encode reply message to store it in the Secure Request: %s", err.Error())
51+
err = fmt.Errorf("Could not JSON encode reply message to store it in the Secure Request: %s", err)
5252
return
5353
}
5454

@@ -59,7 +59,7 @@ func (r *secureRequest) SetMessage(request protocol.Request) (err error) {
5959

6060
signature, err = r.signString([]byte(j))
6161
if err != nil {
62-
err = fmt.Errorf("Could not sign message string: %s", err.Error())
62+
err = fmt.Errorf("Could not sign message string: %s", err)
6363
return
6464
}
6565
r.Signature = base64.StdEncoding.EncodeToString(signature)
@@ -93,7 +93,7 @@ func (r *secureRequest) Valid() bool {
9393

9494
cachedpath, err := r.cacheClientCert()
9595
if err != nil {
96-
log.Errorf("Could not cache Client Certificate: %s", err.Error())
96+
log.Errorf("Could not cache Client Certificate: %s", err)
9797
protocolErrorCtr.Inc()
9898
return false
9999
}
@@ -132,14 +132,14 @@ func (r *secureRequest) JSON() (body string, err error) {
132132
j, err := json.Marshal(r)
133133
if err != nil {
134134
protocolErrorCtr.Inc()
135-
err = fmt.Errorf("Could not JSON Marshal: %s", err.Error())
135+
err = fmt.Errorf("Could not JSON Marshal: %s", err)
136136
return
137137
}
138138

139139
body = string(j)
140140

141141
if err = r.IsValidJSON(body); err != nil {
142-
err = fmt.Errorf("JSON produced from the SecureRequest does not pass validation: %s", err.Error())
142+
err = fmt.Errorf("JSON produced from the SecureRequest does not pass validation: %s", err)
143143
return
144144
}
145145

@@ -156,7 +156,7 @@ func (r *secureRequest) IsValidJSON(data string) (err error) {
156156
_, errors, err := schemas.Validate(schemas.SecureRequestV1, data)
157157
if err != nil {
158158
protocolErrorCtr.Inc()
159-
err = fmt.Errorf("Could not validate SecureRequest JSON data: %s", err.Error())
159+
err = fmt.Errorf("Could not validate SecureRequest JSON data: %s", err)
160160
return
161161
}
162162

@@ -205,14 +205,14 @@ func (r *secureRequest) matchAnyRegex(str []byte, regex []string) bool {
205205
func (r *secureRequest) cacheClientCert() (string, error) {
206206
req, err := NewRequestFromSecureRequest(r)
207207
if err != nil {
208-
log.Errorf("Could not create Request to validate Secure Request with: %s", err.Error())
208+
log.Errorf("Could not create Request to validate Secure Request with: %s", err)
209209
protocolErrorCtr.Inc()
210210
return "", err
211211
}
212212

213213
certname, err := r.requestCallerCertname(req.CallerID())
214214
if err != nil {
215-
log.Errorf("Could not extract certname from caller: %s", err.Error())
215+
log.Errorf("Could not extract certname from caller: %s", err)
216216
protocolErrorCtr.Inc()
217217
return "", err
218218
}
@@ -230,7 +230,7 @@ func (r *secureRequest) cacheClientCert() (string, error) {
230230
err = ioutil.WriteFile(certfile, []byte(r.PublicCertificate), os.FileMode(int(0644)))
231231
if err != nil {
232232
protocolErrorCtr.Inc()
233-
return "", fmt.Errorf("Could not cache client public certificate: %s", err.Error())
233+
return "", fmt.Errorf("Could not cache client public certificate: %s", err)
234234
}
235235

236236
return certfile, nil
@@ -263,28 +263,28 @@ func (r *secureRequest) shouldCacheClientCert(name string) bool {
263263
func (r *secureRequest) verifyCert(certpem []byte, name string) bool {
264264
capem, err := ioutil.ReadFile(r.caPath)
265265
if err != nil {
266-
log.Errorf("Could not read CA '%s': %s", r.caPath, err.Error())
266+
log.Errorf("Could not read CA '%s': %s", r.caPath, err)
267267
protocolErrorCtr.Inc()
268268
return false
269269
}
270270

271271
roots := x509.NewCertPool()
272272
if !roots.AppendCertsFromPEM(capem) {
273-
log.Warnf("Could not use CA '%s' as PEM data: %s", r.caPath, err.Error())
273+
log.Warnf("Could not use CA '%s' as PEM data: %s", r.caPath, err)
274274
protocolErrorCtr.Inc()
275275
return false
276276
}
277277

278278
block, _ := pem.Decode(certpem)
279279
if block == nil {
280-
log.Warnf("Could not decode certificate '%s' PEM data: %s", name, err.Error())
280+
log.Warnf("Could not decode certificate '%s' PEM data: %s", name, err)
281281
protocolErrorCtr.Inc()
282282
return false
283283
}
284284

285285
cert, err := x509.ParseCertificate(block.Bytes)
286286
if err != nil {
287-
log.Warnf("Could not parse certificate '%s': %s", name, err.Error())
287+
log.Warnf("Could not parse certificate '%s': %s", name, err)
288288
protocolErrorCtr.Inc()
289289
return false
290290
}
@@ -300,7 +300,7 @@ func (r *secureRequest) verifyCert(certpem []byte, name string) bool {
300300
_, err = cert.Verify(opts)
301301
if err != nil {
302302
invalidCertificateCtr.Inc()
303-
log.Warnf("Certificate does not pass verification as '%s': %s", name, err.Error())
303+
log.Warnf("Certificate does not pass verification as '%s': %s", name, err)
304304
return false
305305
}
306306

@@ -327,7 +327,7 @@ func (r *secureRequest) decodePEM(certpath string) (pb *pem.Block, err error) {
327327
keydat, err := readFile(certpath)
328328
if err != nil {
329329
protocolErrorCtr.Inc()
330-
return pb, fmt.Errorf("Could not read PEM data from %s: %s", certpath, err.Error())
330+
return pb, fmt.Errorf("Could not read PEM data from %s: %s", certpath, err)
331331
}
332332

333333
pb, _ = pem.Decode(keydat)
@@ -348,7 +348,7 @@ func (r *secureRequest) signString(str []byte) (signature []byte, err error) {
348348
pk, err := x509.ParsePKCS1PrivateKey(pkpem.Bytes)
349349
if err != nil {
350350
protocolErrorCtr.Inc()
351-
err = fmt.Errorf("Could not parse private key PEM data: %s", err.Error())
351+
err = fmt.Errorf("Could not parse private key PEM data: %s", err)
352352
return
353353
}
354354

@@ -357,7 +357,7 @@ func (r *secureRequest) signString(str []byte) (signature []byte, err error) {
357357
signature, err = rsa.SignPKCS1v15(rng, pk, crypto.SHA256, hashed[:])
358358
if err != nil {
359359
protocolErrorCtr.Inc()
360-
err = fmt.Errorf("Could not sign message: %s", err.Error())
360+
err = fmt.Errorf("Could not sign message: %s", err)
361361
}
362362

363363
return
@@ -367,14 +367,14 @@ func (r *secureRequest) verifySignature(str []byte, sig []byte, pubkeyPath strin
367367
pkpem, err := r.decodePEM(pubkeyPath)
368368
if err != nil {
369369
protocolErrorCtr.Inc()
370-
log.Errorf("Could not decode PEM data in public key %s: %s", pubkeyPath, err.Error())
370+
log.Errorf("Could not decode PEM data in public key %s: %s", pubkeyPath, err)
371371
return false
372372
}
373373

374374
cert, err := x509.ParseCertificate(pkpem.Bytes)
375375
if err != nil {
376376
protocolErrorCtr.Inc()
377-
log.Errorf("Could not parse decoded PEM data for public key %s: %s", pubkeyPath, err.Error())
377+
log.Errorf("Could not parse decoded PEM data for public key %s: %s", pubkeyPath, err)
378378
return false
379379
}
380380

@@ -384,13 +384,13 @@ func (r *secureRequest) verifySignature(str []byte, sig []byte, pubkeyPath strin
384384
decodedsig, err := base64.StdEncoding.DecodeString(string(sig))
385385
if err != nil {
386386
protocolErrorCtr.Inc()
387-
log.Errorf("Could not decode signature base64 encoding: %s", err.Error())
387+
log.Errorf("Could not decode signature base64 encoding: %s", err)
388388
return false
389389
}
390390

391391
err = rsa.VerifyPKCS1v15(rsaPublicKey, crypto.SHA256, hashed[:], decodedsig)
392392
if err != nil {
393-
log.Errorf("Verification using %s failed: %s", pubkeyPath, err.Error())
393+
log.Errorf("Verification using %s failed: %s", pubkeyPath, err)
394394
return false
395395
}
396396

@@ -401,7 +401,7 @@ func readFile(path string) (cert []byte, err error) {
401401
cert, err = ioutil.ReadFile(path)
402402
if err != nil {
403403
protocolErrorCtr.Inc()
404-
err = fmt.Errorf("Could not read file %s: %s", path, err.Error())
404+
err = fmt.Errorf("Could not read file %s: %s", path, err)
405405
}
406406

407407
return

0 commit comments

Comments
 (0)