Skip to content

Commit c7cb0b8

Browse files
milan-zededaeriknordmark
authored andcommitted
Beautify error published for failed send operation
Currently, we publish errors like: All attempts to connect to mydomain.adam:3333/api/v2/edgedevice/ping failed: [send via eth1: interface eth1: no DNS server available send via eth0 with src IP 172.22.12.10: Get \"https://mydomain.adam:3333/api/v2/edgedevice/ping\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)] It is hard to read, contains stutter, uses square brackets, separates errors with only a single space and all of that makes it difficult to read. Such error is not nice to display in the controller UI for example. Signed-off-by: Milan Lenco <milan@zededa.com>
1 parent 4846c84 commit c7cb0b8

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

pkg/pillar/zedcloud/send.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ func SendOnAllIntf(ctxWork context.Context, ctx *ZedCloudContext, url string, re
260260
combinedRV.RespContents = rv.RespContents
261261
return combinedRV, nil
262262
}
263-
errStr := fmt.Sprintf("All attempts to connect to %s failed: %v",
264-
url, attempts)
263+
errStr := fmt.Sprintf("All attempts to connect to %s failed: %s",
264+
url, describeSendAttempts(attempts))
265265
log.Errorln(errStr)
266266
err := &SendError{
267267
Err: errors.New(errStr),
@@ -438,8 +438,8 @@ func VerifyAllIntf(ctx *ZedCloudContext, url string, requiredSuccessCount uint,
438438
return verifyRV, err
439439
}
440440
if intfSuccessCount == 0 {
441-
errStr := fmt.Sprintf("All attempts to connect to %s failed: %v",
442-
url, attempts)
441+
errStr := fmt.Sprintf("All attempts to connect to %s failed: %s",
442+
url, describeSendAttempts(attempts))
443443
log.Errorln(errStr)
444444
err := &SendError{
445445
Err: errors.New(errStr),
@@ -1117,8 +1117,8 @@ func SendOnIntf(workContext context.Context, ctx *ZedCloudContext, destURL strin
11171117
if ctx.FailureFunc != nil {
11181118
ctx.FailureFunc(log, intf, reqURL, 0, 0, false)
11191119
}
1120-
errStr := fmt.Sprintf("All attempts to connect to %s failed: %v",
1121-
reqURL, attempts)
1120+
errStr := fmt.Sprintf("All attempts to connect to %s failed: %s",
1121+
reqURL, describeSendAttempts(attempts))
11221122
log.Errorln(errStr)
11231123
err = &SendError{
11241124
Err: errors.New(errStr),
@@ -1353,6 +1353,30 @@ func isECONNREFUSED(err error) bool {
13531353
return errno == syscall.ECONNREFUSED
13541354
}
13551355

1356+
// Describe send attempts in a concise and readable form.
1357+
func describeSendAttempts(attempts []SendAttempt) string {
1358+
var attemptDescriptions []string
1359+
for _, attempt := range attempts {
1360+
var description string
1361+
// Unwrap errors defined here in pillar to avoid stutter.
1362+
// Instead of "send via eth1: interface eth1: no DNS server available",
1363+
// we simply return "interface eth1: no DNS server available".
1364+
// Same for IPAddrNotAvail.
1365+
// Otherwise, the errors are of the form:
1366+
// "send via eth1 [with src IP <IP>]: <error from http client>"
1367+
switch err := attempt.Err.(type) {
1368+
case *types.DNSNotAvail:
1369+
description = err.Error()
1370+
case *types.IPAddrNotAvail:
1371+
description = err.Error()
1372+
default:
1373+
description = attempt.String()
1374+
}
1375+
attemptDescriptions = append(attemptDescriptions, description)
1376+
}
1377+
return strings.Join(attemptDescriptions, "; ")
1378+
}
1379+
13561380
// NewContext - return initialized cloud context
13571381
func NewContext(log *base.LogObject, opt ContextOptions) ZedCloudContext {
13581382
ctx := ZedCloudContext{

0 commit comments

Comments
 (0)