chore: do not use sentinel errors when unneeded

- main reason being it's a burden to always define sentinel errors at global scope, wrap them with `%w` instead of using a string directly
- only use sentinel errors when it has to be checked using `errors.Is`
- replace all usage of these sentinel errors in `fmt.Errorf` with direct strings that were in the sentinel error
- exclude the sentinel error definition requirement from .golangci.yml
- update unit tests to use ContainersError instead of ErrorIs so it stays as a "not a change detector test" without requiring a sentinel error
This commit is contained in:
Quentin McGaw
2026-05-02 00:50:16 +00:00
parent 9b6f048fe8
commit 4a78989d9d
172 changed files with 666 additions and 1433 deletions
+1 -7
View File
@@ -2,7 +2,6 @@ package resolver
import (
"context"
"errors"
"fmt"
"net/netip"
)
@@ -34,11 +33,6 @@ type parallelResult struct {
IPs []netip.Addr
}
var (
ErrMinFound = errors.New("not enough hosts found")
ErrMaxFailRatio = errors.New("maximum failure ratio reached")
)
func (pr *Parallel) Resolve(ctx context.Context, settings ParallelSettings) (
hostToIPs map[string][]netip.Addr, warnings []string, err error,
) {
@@ -90,7 +84,7 @@ func (pr *Parallel) Resolve(ctx context.Context, settings ParallelSettings) (
failureRatio := float64(len(warnings)) / float64(len(settings.Hosts))
if failureRatio > settings.MaxFailRatio {
return hostToIPs, warnings,
fmt.Errorf("%w: %.2f failure ratio reached", ErrMaxFailRatio, failureRatio)
fmt.Errorf("maximum failure ratio reached: %.2f failure ratio reached", failureRatio)
}
return hostToIPs, warnings, nil
+5 -10
View File
@@ -2,7 +2,6 @@ package resolver
import (
"context"
"errors"
"fmt"
"net"
"net/netip"
@@ -62,11 +61,6 @@ func (r *Repeat) Resolve(ctx context.Context, host string, settings RepeatSettin
return ips, nil
}
var (
ErrMaxNoNew = errors.New("reached the maximum number of no new update")
ErrMaxFails = errors.New("reached the maximum number of consecutive failures")
)
func (r *Repeat) resolveOnce(ctx, timedCtx context.Context, host string,
settings RepeatSettings, uniqueIPs map[string]struct{}, noNewCounter, failCounter int) (
newNoNewCounter, newFailCounter int, err error,
@@ -75,8 +69,8 @@ func (r *Repeat) resolveOnce(ctx, timedCtx context.Context, host string,
if err != nil {
failCounter++
if settings.MaxFails > 0 && failCounter == settings.MaxFails {
return noNewCounter, failCounter, fmt.Errorf("%w: %d failed attempts resolving %s: %s",
ErrMaxFails, settings.MaxFails, host, err)
return noNewCounter, failCounter, fmt.Errorf("reached the maximum number of consecutive failures: "+
"%d failed attempts resolving %s: %s", settings.MaxFails, host, err)
}
// it's fine to fail some of the resolutions
return noNewCounter, failCounter, nil
@@ -100,8 +94,9 @@ func (r *Repeat) resolveOnce(ctx, timedCtx context.Context, host string,
// we reached the maximum number of resolutions without
// finding any new IP address to our unique IP addresses set.
return noNewCounter, failCounter,
fmt.Errorf("%w: %d times no updated for %d IP addresses found",
ErrMaxNoNew, noNewCounter, len(uniqueIPs))
fmt.Errorf("reached the maximum number of no new update: "+
"%d times no updated for %d IP addresses found",
noNewCounter, len(uniqueIPs))
}
timer := time.NewTimer(settings.BetweenDuration)