cloudstack-go icon indicating copy to clipboard operation
cloudstack-go copied to clipboard

GetVirtualMachinesMetricID method throwing panic error when accessing VMs from reponse

Open rajeshvenkata opened this issue 11 months ago • 2 comments

Problem: VirtualMachineService.GetVirtualMachinesMetricID method throws panic when it is trying to access the VMs response from server in below line of code. This happens when the count in the response is 1 but the actual VirtualMachinesMetrics array in the reponse is nil or empty. This is causing panic in the caller CAPC

panic error is happening at: https://github.com/apache/cloudstack-go/blob/main/cloudstack/VirtualMachineService.go#L5543

error: panic: runtime error: index out of range [0] with length 0

version of cloudstack-go used: 2.16.1

Please help investigate this error and let us know if this response is not expected

rajeshvenkata avatar Feb 26 '25 19:02 rajeshvenkata

@rajeshvenkata Can you please post the response of list virtualmachinesmetrics name=<name_of_the_vm> using Cloudmonkey - the CLI. Because, it is quite odd that count is 1, but it fails to retrieve the VM id.

Pearl1594 avatar Feb 26 '25 20:02 Pearl1594

@Pearl1594 Thanks for looking into this. Sure, I will try to get the response from the customer. In the meanwhile, should the code also be checking if array is nil or empty before accessing the VM array in the response? Or do you think this should not happen ideally?

rajeshvenkata avatar Feb 26 '25 21:02 rajeshvenkata