Skip to content

Commit

Permalink
optimize(host): wrap updateOrCreateHost error (#21142)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi authored Sep 2, 2024
1 parent 4ea3d11 commit 8564725
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/hostman/hostinfo/hostinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit 8564725

Please sign in to comment.