Skip to content

Commit

Permalink
Beautify error published for failed send operation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
milan-zededa authored and eriknordmark committed Jul 22, 2023
1 parent 4846c84 commit c7cb0b8
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions pkg/pillar/zedcloud/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ func SendOnAllIntf(ctxWork context.Context, ctx *ZedCloudContext, url string, re
combinedRV.RespContents = rv.RespContents
return combinedRV, nil
}
errStr := fmt.Sprintf("All attempts to connect to %s failed: %v",
url, attempts)
errStr := fmt.Sprintf("All attempts to connect to %s failed: %s",
url, describeSendAttempts(attempts))
log.Errorln(errStr)
err := &SendError{
Err: errors.New(errStr),
Expand Down Expand Up @@ -438,8 +438,8 @@ func VerifyAllIntf(ctx *ZedCloudContext, url string, requiredSuccessCount uint,
return verifyRV, err
}
if intfSuccessCount == 0 {
errStr := fmt.Sprintf("All attempts to connect to %s failed: %v",
url, attempts)
errStr := fmt.Sprintf("All attempts to connect to %s failed: %s",
url, describeSendAttempts(attempts))
log.Errorln(errStr)
err := &SendError{
Err: errors.New(errStr),
Expand Down Expand Up @@ -1117,8 +1117,8 @@ func SendOnIntf(workContext context.Context, ctx *ZedCloudContext, destURL strin
if ctx.FailureFunc != nil {
ctx.FailureFunc(log, intf, reqURL, 0, 0, false)
}
errStr := fmt.Sprintf("All attempts to connect to %s failed: %v",
reqURL, attempts)
errStr := fmt.Sprintf("All attempts to connect to %s failed: %s",
reqURL, describeSendAttempts(attempts))
log.Errorln(errStr)
err = &SendError{
Err: errors.New(errStr),
Expand Down Expand Up @@ -1353,6 +1353,30 @@ func isECONNREFUSED(err error) bool {
return errno == syscall.ECONNREFUSED
}

// Describe send attempts in a concise and readable form.
func describeSendAttempts(attempts []SendAttempt) string {
var attemptDescriptions []string
for _, attempt := range attempts {
var description string
// Unwrap errors defined here in pillar to avoid stutter.
// Instead of "send via eth1: interface eth1: no DNS server available",
// we simply return "interface eth1: no DNS server available".
// Same for IPAddrNotAvail.
// Otherwise, the errors are of the form:
// "send via eth1 [with src IP <IP>]: <error from http client>"
switch err := attempt.Err.(type) {
case *types.DNSNotAvail:
description = err.Error()
case *types.IPAddrNotAvail:
description = err.Error()
default:
description = attempt.String()
}
attemptDescriptions = append(attemptDescriptions, description)
}
return strings.Join(attemptDescriptions, "; ")
}

// NewContext - return initialized cloud context
func NewContext(log *base.LogObject, opt ContextOptions) ZedCloudContext {
ctx := ZedCloudContext{
Expand Down

0 comments on commit c7cb0b8

Please sign in to comment.