mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-10-12 01:58:46 +02:00
fix(cli): skip DNS restoration quietly when the interface is gone
A successful macOS upgrade printed "could not get interface error=interface not found iface=en5" before reporting success, because the DNS cleanup logged every interface lookup failure at error level. An interface that is gone, an unplugged adapter or a torn down tether, has no DNS settings left to restore, so the skip is now a debug diagnostic naming the interface and the work it skipped. Only that condition is quiet. netInterface returns a sentinel error for a missing interface and no longer reports a failed enumeration as one, so any other lookup failure and any restoration failure on an interface that does exist stay at error level.
This commit is contained in:
3 files changed
+171
-3
No files matched your search
+17
-1
@@ -1810,6 +1810,22 @@ func (p *prog) resetDNS(isStart bool, restoreStatic bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// logIfaceLookupFailure reports a failed lookup of the interface the caller was
|
||||
// about to work on, naming that work in skipping, e.g. "DNS restoration". An
|
||||
// interface that no longer exists has nothing left to act on — an unplugged
|
||||
// adapter or a torn down tether is gone along with the settings ctrld changed —
|
||||
// so the skip is a debug diagnostic rather than a user-facing error: it
|
||||
// otherwise makes a successful upgrade look broken. Every other lookup failure
|
||||
// still says something went wrong and stays at error level, as does a failure
|
||||
// on an interface that does exist.
|
||||
func logIfaceLookupFailure(logger *zerolog.Logger, skipping string, err error) {
|
||||
if errors.Is(err, errInterfaceNotFound) {
|
||||
logger.Debug().Msgf("Skipping %s: previous interface is no longer present", skipping)
|
||||
return
|
||||
}
|
||||
logger.Error().Err(err).Msg("could not get interface")
|
||||
}
|
||||
|
||||
// resetDNSForRunningIface performs a DNS reset on the running interface.
|
||||
// The parameter isStart indicates whether this is being called as part of a start (or restart)
|
||||
// command. When true, we check if the current static DNS configuration already differs from the
|
||||
@@ -1824,7 +1840,7 @@ func (p *prog) resetDNSForRunningIface(isStart bool, restoreStatic bool) (runnin
|
||||
logger := mainLog.Load().With().Str("iface", p.runningIface).Logger()
|
||||
netIface, err := netInterface(p.runningIface)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not get interface")
|
||||
logIfaceLookupFailure(&logger, "DNS restoration", err)
|
||||
return
|
||||
}
|
||||
runningIface = netIface
|
||||
|
||||
Reference in new issue
Block a user