mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
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:
committed by
Cuong Manh Le
parent
35e2a20019
commit
2996a161cd
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user