poller error formatting

This commit is contained in:
yusing 2025-02-13 23:31:00 +08:00
parent 3bd8aca2d2
commit 40c4344f73

View file

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"net/url" "net/url"
"strings"
"time" "time"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/logging" "github.com/yusing/go-proxy/internal/logging"
"github.com/yusing/go-proxy/internal/task" "github.com/yusing/go-proxy/internal/task"
) )
@ -85,13 +85,11 @@ func (p *Poller[T, AggregateT]) gatherErrs() (string, bool) {
if len(p.errs) == 0 { if len(p.errs) == 0 {
return "", false return "", false
} }
title := fmt.Sprintf("Poller %s has encountered %d errors in the last %s seconds:", p.name, len(p.errs), gatherErrsInterval) errs := E.NewBuilder(fmt.Sprintf("poller %s has encountered %d errors in the last %s:", p.name, len(p.errs), gatherErrsInterval))
errs := make([]string, 0, len(p.errs)+1)
errs = append(errs, title)
for _, e := range p.errs { for _, e := range p.errs {
errs = append(errs, fmt.Sprintf("%s: %d times", e.err.Error(), e.count)) errs.Addf("%w: %d times", e.err, e.count)
} }
return strings.Join(errs, "\n"), true return errs.String(), true
} }
func (p *Poller[T, AggregateT]) clearErrs() { func (p *Poller[T, AggregateT]) clearErrs() {