Fix tautological condition in findWorkingInterface

- Add explicit foundDefaultRoute boolean variable to track default route discovery
- Initialize foundDefaultRoute to false and set to true only in success case
- Replace tautological condition `err == nil` with meaningful `foundDefaultRoute` check
- Fixes "tautological condition: nil == nil" linter error

The error occurred because err was being reused from net.Interfaces() call,
making the condition always true. Now we explicitly track whether a default
route was successfully found.
This commit is contained in:
Cuong Manh Le
2025-07-16 17:27:27 +07:00
committed by Cuong Manh Le
parent 35e2a20019
commit 2996a161cd

View File

@@ -1042,12 +1042,14 @@ func (p *prog) findWorkingInterface() string {
}
// Get default route interface
foundDefaultRoute := false
defaultRoute, err := netmon.DefaultRoute()
if err != nil {
p.Debug().
Err(err).
Msg("failed to get default route")
} else {
foundDefaultRoute = true
p.Debug().
Str("default_route_iface", defaultRoute.InterfaceName).
Msg("found default route")
@@ -1084,7 +1086,7 @@ func (p *prog) findWorkingInterface() string {
}
// Found working physical interface
if err == nil && defaultRoute.InterfaceName == iface.Name {
if foundDefaultRoute && defaultRoute.InterfaceName == iface.Name {
// Found interface with default route - use it immediately
p.Info().
Str("old_iface", currentIface).