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 48d0558103
commit 016c566307
+3 -1
View File
@@ -1042,12 +1042,14 @@ func (p *prog) findWorkingInterface() string {
} }
// Get default route interface // Get default route interface
foundDefaultRoute := false
defaultRoute, err := netmon.DefaultRoute() defaultRoute, err := netmon.DefaultRoute()
if err != nil { if err != nil {
p.Debug(). p.Debug().
Err(err). Err(err).
Msg("failed to get default route") Msg("failed to get default route")
} else { } else {
foundDefaultRoute = true
p.Debug(). p.Debug().
Str("default_route_iface", defaultRoute.InterfaceName). Str("default_route_iface", defaultRoute.InterfaceName).
Msg("found default route") Msg("found default route")
@@ -1084,7 +1086,7 @@ func (p *prog) findWorkingInterface() string {
} }
// Found working physical interface // 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 // Found interface with default route - use it immediately
p.Info(). p.Info().
Str("old_iface", currentIface). Str("old_iface", currentIface).