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
+3 -7
View File
@@ -11,14 +11,11 @@ import (
"strconv"
"time"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/utils"
)
var regexPort = regexp.MustCompile(`[1-9][0-9]{0,4}`)
var ErrPortForwardedNotFound = errors.New("port forwarded not found")
// PortForward obtains a VPN server side port forwarded from the PrivateVPN API.
// It returns 0 if all ports are to forwarded on a dedicated server IP.
func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObjects) (
@@ -42,8 +39,7 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj
}
if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%w: %d %s", common.ErrHTTPStatusCodeNotOK,
response.StatusCode, response.Status)
return nil, fmt.Errorf("HTTP status code not OK: %d %s", response.StatusCode, response.Status)
}
defer response.Body.Close()
@@ -62,12 +58,12 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj
return nil, fmt.Errorf("decoding JSON response: %w; data is: %s",
err, string(bytes))
} else if !data.Supported {
return nil, fmt.Errorf("%w for this VPN server", common.ErrPortForwardNotSupported)
return nil, errors.New("port forwarding not supported for this VPN server")
}
portString := regexPort.FindString(data.Status)
if portString == "" {
return nil, fmt.Errorf("%w: in status %q", ErrPortForwardedNotFound, data.Status)
return nil, fmt.Errorf("port forwarded not found in status %q", data.Status)
}
const base, bitSize = 10, 16