mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-07 04:20:12 +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:
@@ -64,14 +64,6 @@ func (s *Settings) OverrideWith(other Settings) {
|
||||
s.ShutdownTimeout = gosettings.OverrideWithComparable(s.ShutdownTimeout, other.ShutdownTimeout)
|
||||
}
|
||||
|
||||
var (
|
||||
ErrHandlerIsNotSet = errors.New("HTTP handler cannot be left unset")
|
||||
ErrLoggerIsNotSet = errors.New("logger cannot be left unset")
|
||||
ErrReadHeaderTimeoutTooSmall = errors.New("read header timeout is too small")
|
||||
ErrReadTimeoutTooSmall = errors.New("read timeout is too small")
|
||||
ErrShutdownTimeoutTooSmall = errors.New("shutdown timeout is too small")
|
||||
)
|
||||
|
||||
func (s Settings) Validate() (err error) {
|
||||
err = validate.ListeningAddress(s.Address, os.Getuid())
|
||||
if err != nil {
|
||||
@@ -79,31 +71,25 @@ func (s Settings) Validate() (err error) {
|
||||
}
|
||||
|
||||
if s.Handler == nil {
|
||||
return fmt.Errorf("%w", ErrHandlerIsNotSet)
|
||||
return errors.New("HTTP handler cannot be left unset")
|
||||
}
|
||||
|
||||
if s.Logger == nil {
|
||||
return fmt.Errorf("%w", ErrLoggerIsNotSet)
|
||||
return errors.New("logger cannot be left unset")
|
||||
}
|
||||
|
||||
const minReadTimeout = time.Millisecond
|
||||
if s.ReadHeaderTimeout < minReadTimeout {
|
||||
return fmt.Errorf("%w: %s must be at least %s",
|
||||
ErrReadHeaderTimeoutTooSmall,
|
||||
s.ReadHeaderTimeout, minReadTimeout)
|
||||
return fmt.Errorf("read header timeout is too small: %s must be at least %s", s.ReadHeaderTimeout, minReadTimeout)
|
||||
}
|
||||
|
||||
if s.ReadTimeout < minReadTimeout {
|
||||
return fmt.Errorf("%w: %s must be at least %s",
|
||||
ErrReadTimeoutTooSmall,
|
||||
s.ReadTimeout, minReadTimeout)
|
||||
return fmt.Errorf("read timeout is too small: %s must be at least %s", s.ReadTimeout, minReadTimeout)
|
||||
}
|
||||
|
||||
const minShutdownTimeout = 5 * time.Millisecond
|
||||
if s.ShutdownTimeout < minShutdownTimeout {
|
||||
return fmt.Errorf("%w: %s must be at least %s",
|
||||
ErrShutdownTimeoutTooSmall,
|
||||
s.ShutdownTimeout, minShutdownTimeout)
|
||||
return fmt.Errorf("shutdown timeout is too small: %s must be at least %s", s.ShutdownTimeout, minShutdownTimeout)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user