Check GetDomain and GetDomainStats response not to be nil
@@ -200,7 +200,7 @@ func handleError(err error, cmdName string, response *cmdv1.Response) error {
} else if err != nil {
msg := fmt.Sprintf("unknown error encountered sending command %s: %s", cmdName, err.Error())
return fmt.Errorf(msg)
- } else if response.Success != true {
+ } else if response != nil && response.Success != true {
return fmt.Errorf("server error. command %s failed: %q", cmdName, response.Message)
}
return nil
@@ -300,14 +300,19 @@ func (c *VirtLauncherClient) GetDomain() (*api.Domain, bool, error) {
request := &cmdv1.EmptyRequest{}
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
defer cancel()
- response, err := c.v1client.GetDomain(ctx, request)
- if err = handleError(err, "GetDomain", response.Response); err != nil {
+ domainResponse, err := c.v1client.GetDomain(ctx, request)
+ var response *cmdv1.Response
+ if domainResponse != nil {
+ response = domainResponse.Response
+ }
+
+ if err = handleError(err, "GetDomain", response); err != nil {
return domain, exists, err
}
- if response.Domain != "" {
- if err := json.Unmarshal([]byte(response.Domain), domain); err != nil {
+ if domainResponse.Domain != "" {
+ if err := json.Unmarshal([]byte(domainResponse.Domain), domain); err != nil {
log.Log.Reason(err).Error("error unmarshalling domain")
return domain, exists, err
}
@@ -323,14 +328,19 @@ func (c *VirtLauncherClient) GetDomainStats() (*stats.DomainStats, bool, error)
request := &cmdv1.EmptyRequest{}
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
defer cancel()
- response, err := c.v1client.GetDomainStats(ctx, request)
- if err = handleError(err, "GetDomainStats", response.Response); err != nil {
+ domainStatsRespose, err := c.v1client.GetDomainStats(ctx, request)
+ var response *cmdv1.Response
+ if domainStatsRespose != nil {
+ response = domainStatsRespose.Response
+ }
+
+ if err = handleError(err, "GetDomainStats", response); err != nil {
return stats, exists, err
}
- if response.DomainStats != "" {
- if err := json.Unmarshal([]byte(response.DomainStats), stats); err != nil {
+ if domainStatsRespose.DomainStats != "" {
+ if err := json.Unmarshal([]byte(domainStatsRespose.DomainStats), stats); err != nil {
log.Log.Reason(err).Error("error unmarshalling domain")
return stats, exists, err
}
