mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-20 11:02:59 +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:
@@ -13,11 +13,6 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/pmtud/tcp"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrICMPOkTCPFail = errors.New("PMTUD succeeded with ICMP but failed with TCP")
|
||||
ErrICMPFailTCPFail = errors.New("PMTUD failed with both ICMP and TCP")
|
||||
)
|
||||
|
||||
// PathMTUDiscover discovers the maximum MTU using both ICMP and TCP.
|
||||
// Multiple ICMP addresses and TCP addresses can be specified for redundancy.
|
||||
// ICMP PMTUD is run first. If successful, the range of possible MTU values to
|
||||
@@ -81,10 +76,10 @@ func PathMTUDiscover(ctx context.Context, icmpAddrs []netip.Addr, tcpAddrs []net
|
||||
}
|
||||
}
|
||||
if icmpSuccess {
|
||||
return 0, fmt.Errorf("%w - discarding ICMP obtained MTU %d",
|
||||
ErrICMPOkTCPFail, maxPossibleMTU)
|
||||
return 0, fmt.Errorf("PMTUD succeeded with ICMP but failed with TCP "+
|
||||
"- discarding ICMP obtained MTU %d", maxPossibleMTU)
|
||||
}
|
||||
return 0, fmt.Errorf("%w", ErrICMPFailTCPFail)
|
||||
return 0, errors.New("PMTUD failed with both ICMP and TCP")
|
||||
}
|
||||
logger.Debugf("TCP path MTU discovery found maximum valid MTU %d", mtu)
|
||||
return mtu, nil
|
||||
|
||||
Reference in New Issue
Block a user