chore(errors): review all errors in codebase
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
@@ -9,12 +8,6 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/netlink"
|
||||
)
|
||||
|
||||
var (
|
||||
errLinkByName = errors.New("cannot obtain link by name")
|
||||
errRouteAdd = errors.New("cannot add route")
|
||||
errRouteDelete = errors.New("cannot delete route")
|
||||
)
|
||||
|
||||
func (r *Routing) addRouteVia(destination net.IPNet, gateway net.IP,
|
||||
iface string, table int) error {
|
||||
destinationStr := destination.String()
|
||||
@@ -26,7 +19,7 @@ func (r *Routing) addRouteVia(destination net.IPNet, gateway net.IP,
|
||||
|
||||
link, err := r.netLinker.LinkByName(iface)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: interface %s: %s", errLinkByName, iface, err)
|
||||
return fmt.Errorf("cannot find link for interface %s: %w", iface, err)
|
||||
}
|
||||
|
||||
route := netlink.Route{
|
||||
@@ -36,8 +29,8 @@ func (r *Routing) addRouteVia(destination net.IPNet, gateway net.IP,
|
||||
Table: table,
|
||||
}
|
||||
if err := r.netLinker.RouteReplace(&route); err != nil {
|
||||
return fmt.Errorf("%w: for subnet %s at interface %s",
|
||||
err, destinationStr, iface)
|
||||
return fmt.Errorf("cannot replace route for subnet %s at interface %s: %w",
|
||||
destinationStr, iface, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -54,7 +47,7 @@ func (r *Routing) deleteRouteVia(destination net.IPNet, gateway net.IP,
|
||||
|
||||
link, err := r.netLinker.LinkByName(iface)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: for interface %s: %s", errLinkByName, iface, err)
|
||||
return fmt.Errorf("cannot find link for interface %s: %w", iface, err)
|
||||
}
|
||||
|
||||
route := netlink.Route{
|
||||
@@ -64,8 +57,8 @@ func (r *Routing) deleteRouteVia(destination net.IPNet, gateway net.IP,
|
||||
Table: table,
|
||||
}
|
||||
if err := r.netLinker.RouteDel(&route); err != nil {
|
||||
return fmt.Errorf("%w: for subnet %s at interface %s",
|
||||
err, destinationStr, iface)
|
||||
return fmt.Errorf("cannot delete route: for subnet %s at interface %s: %w",
|
||||
destinationStr, iface, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user