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:
Cuong Manh Le committed 2026-09-28 16:50:39 +07:00
1 parent 9db6de060f
commit 6eed09338d
3 files changed
+171 -3

No files matched your search

+13 -2
View File
@@ -1142,6 +1142,12 @@ func processLogAndCacheFlags(v *viper.Viper, cfg *ctrld.Config) {
v.Set("service", cfg.Service)
}
// errInterfaceNotFound reports that the named interface does not exist on the
// host. Callers use errors.Is to tell this apart from a lookup that failed for
// another reason, because an interface that is simply gone (an unplugged
// adapter, a torn down tether) is an expected outcome rather than a failure.
var errInterfaceNotFound = errors.New("interface not found")
func netInterface(ifaceName string) (*net.Interface, error) {
if ifaceName == autoIface {
ifaceName = defaultIfaceName()
@@ -1152,13 +1158,18 @@ func netInterface(ifaceName string) (*net.Interface, error) {
iface = i.Interface
}
})
if err != nil {
// Enumeration itself failed, so the interface cannot be reported as
// missing: nothing was positively established about it.
return nil, err
}
if iface == nil {
return nil, errors.New("interface not found")
return nil, errInterfaceNotFound
}
if _, err := patchNetIfaceName(iface); err != nil {
return nil, err
}
return iface, err
return iface, nil
}
func defaultIfaceName() string {