mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-09 20:29:23 +02:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user