chore(errors): review all errors in codebase
This commit is contained in:
@@ -2,7 +2,6 @@ package vpn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
@@ -12,14 +11,6 @@ import (
|
||||
"github.com/qdm12/golibs/command"
|
||||
)
|
||||
|
||||
var (
|
||||
errServerConn = errors.New("failed finding a valid server connection")
|
||||
errBuildConfig = errors.New("failed building configuration")
|
||||
errWriteConfig = errors.New("failed writing configuration to file")
|
||||
errWriteAuth = errors.New("failed writing auth to file")
|
||||
errFirewall = errors.New("failed allowing VPN connection through firewall")
|
||||
)
|
||||
|
||||
// setupOpenVPN sets OpenVPN up using the configurators and settings given.
|
||||
// It returns a serverName for port forwarding (PIA) and an error if it fails.
|
||||
func setupOpenVPN(ctx context.Context, fw firewall.VPNConnectionSetter,
|
||||
@@ -28,27 +19,27 @@ func setupOpenVPN(ctx context.Context, fw firewall.VPNConnectionSetter,
|
||||
runner vpnRunner, serverName string, err error) {
|
||||
connection, err := providerConf.GetConnection(settings.Provider.ServerSelection)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %s", errServerConn, err)
|
||||
return nil, "", fmt.Errorf("failed finding a valid server connection: %w", err)
|
||||
}
|
||||
|
||||
lines, err := providerConf.BuildConf(connection, settings.OpenVPN)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %s", errBuildConfig, err)
|
||||
return nil, "", fmt.Errorf("failed building configuration: %w", err)
|
||||
}
|
||||
|
||||
if err := openvpnConf.WriteConfig(lines); err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %s", errWriteConfig, err)
|
||||
return nil, "", fmt.Errorf("failed writing configuration to file: %w", err)
|
||||
}
|
||||
|
||||
if settings.OpenVPN.User != "" {
|
||||
err := openvpnConf.WriteAuthFile(settings.OpenVPN.User, settings.OpenVPN.Password)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %s", errWriteAuth, err)
|
||||
return nil, "", fmt.Errorf("failed writing auth to file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := fw.SetVPNConnection(ctx, connection, settings.OpenVPN.Interface); err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %s", errFirewall, err)
|
||||
return nil, "", fmt.Errorf("failed allowing VPN connection through firewall: %w", err)
|
||||
}
|
||||
|
||||
runner = openvpn.NewRunner(settings.OpenVPN, starter, logger)
|
||||
|
||||
Reference in New Issue
Block a user