[client] Publish the network selection event on a partial failure

Returning early on error was correct while an error meant nothing had
happened. A partial failure now changes the selection and the routing
table, so returning first left the change with no trace in the event log
or the UI, even though the new state had already been broadcast.
This commit is contained in:
Maxim Egorov
2026-08-28 12:45:38 +02:00
parent 4a518b2868
commit 2621959252

View File

@@ -160,12 +160,16 @@ func (s *Server) SelectNetworks(_ context.Context, req *proto.SelectNetworksRequ
return nil, fmt.Errorf("no route manager")
}
var selectErr error
if req.GetAll() {
routeManager.SelectAllRoutes()
} else if err := routeManager.SelectRoutes(toNetIDs(req.GetNetworkIDs()), req.GetAppend()); err != nil {
return nil, err
} else {
selectErr = routeManager.SelectRoutes(toNetIDs(req.GetNetworkIDs()), req.GetAppend())
}
// A partial failure (e.g. an unknown ID in the request) still changes the selection,
// so the event must be published regardless of selectErr, or the change leaves no
// trace in the event log/UI even though it already reached the routing table.
s.statusRecorder.PublishEvent(
proto.SystemEvent_INFO,
proto.SystemEvent_SYSTEM,
@@ -178,6 +182,10 @@ func (s *Server) SelectNetworks(_ context.Context, req *proto.SelectNetworksRequ
},
)
if selectErr != nil {
return nil, selectErr
}
return &proto.SelectNetworksResponse{}, nil
}
@@ -204,12 +212,16 @@ func (s *Server) DeselectNetworks(_ context.Context, req *proto.SelectNetworksRe
return nil, fmt.Errorf("no route manager")
}
var deselectErr error
if req.GetAll() {
routeManager.DeselectAllRoutes()
} else if err := routeManager.DeselectRoutes(toNetIDs(req.GetNetworkIDs())); err != nil {
return nil, err
} else {
deselectErr = routeManager.DeselectRoutes(toNetIDs(req.GetNetworkIDs()))
}
// A partial failure (e.g. an unknown ID in the request) still changes the selection,
// so the event must be published regardless of deselectErr, or the change leaves no
// trace in the event log/UI even though it already reached the routing table.
s.statusRecorder.PublishEvent(
proto.SystemEvent_INFO,
proto.SystemEvent_SYSTEM,
@@ -222,6 +234,10 @@ func (s *Server) DeselectNetworks(_ context.Context, req *proto.SelectNetworksRe
},
)
if deselectErr != nil {
return nil, deselectErr
}
return &proto.SelectNetworksResponse{}, nil
}