mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-06 20:10:11 +02:00
4a78989d9d
- 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
29 lines
835 B
Go
29 lines
835 B
Go
package icmp
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrNotPermitted = errors.New("ICMP not permitted")
|
|
errCommunicationAdministrativelyProhibited = errors.New("communication administratively prohibited")
|
|
ErrMTUNotFound = errors.New("MTU not found")
|
|
errTimeout = errors.New("operation timed out")
|
|
)
|
|
|
|
func wrapConnErr(err error, timedCtx context.Context, pingTimeout time.Duration) error { //nolint:revive
|
|
switch {
|
|
case strings.HasSuffix(err.Error(), "sendto: operation not permitted"):
|
|
err = fmt.Errorf("%w", ErrNotPermitted)
|
|
case errors.Is(timedCtx.Err(), context.DeadlineExceeded):
|
|
err = fmt.Errorf("%w: after %s", errTimeout, pingTimeout)
|
|
case timedCtx.Err() != nil:
|
|
err = timedCtx.Err()
|
|
}
|
|
return err
|
|
}
|