optimize(host): wrap updateOrCreateHost error (#21141)

This commit is contained in:
Zexi Li
2024-09-02 13:28:28 +08:00
committed by GitHub
parent 07df2aac53
commit 29054379a9
+11 -4
View File
@@ -1417,7 +1417,11 @@ func (h *SHostInfo) ensureHostRecord(zoneId string) (*api.HostDetails, error) {
}
}
return h.updateOrCreateHost(h.HostId)
host, err := h.updateOrCreateHost(h.HostId)
if err != nil {
return nil, errors.Wrap(err, "updateOrCreateHost")
}
return host, nil
}
func (h *SHostInfo) UpdateSyncInfo(hostId string, body jsonutils.JSONObject) (interface{}, error) {
@@ -1561,11 +1565,14 @@ func (h *SHostInfo) updateOrCreateHost(hostId string) (*api.HostDetails, error)
)
if !h.isInit {
res, err = modules.Hosts.Update(h.GetSession(), hostId, jsonutils.Marshal(input))
if err != nil {
return nil, errors.Wrapf(err, "update host with input: %s", jsonutils.Marshal(input))
}
} else {
res, err = modules.Hosts.CreateInContext(h.GetSession(), jsonutils.Marshal(input), &modules.Zones, h.ZoneId)
}
if err != nil {
return nil, errors.Wrapf(err, "host create or update with %s", jsonutils.Marshal(input))
if err != nil {
return nil, errors.Wrapf(err, "create host with zone: %q, input: %s", h.ZoneId, jsonutils.Marshal(input))
}
}
hostDetails := api.HostDetails{}