From 856472584583a6acb242699acb7dd86c839c1845 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Mon, 2 Sep 2024 13:28:38 +0800 Subject: [PATCH] optimize(host): wrap updateOrCreateHost error (#21142) --- pkg/hostman/hostinfo/hostinfo.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index 6dcad954d85..aa2c9ad2353 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -1409,7 +1409,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) { @@ -1553,11 +1557,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{}