jmsperu commented on issue #103:
URL: https://github.com/apache/cloudstack-go/issues/103#issuecomment-4757282931
@rajeshvenkata your read was right — the helper should check the slice
before indexing it. Opened #152 to do exactly that.
The `Get<Entity>ID` helpers are generated, so the fix is in the generator
template: a `len(...) == 0` guard before the `[0]` access, returning the same
`No match found` error already used for the `count == 0` case (applied to all
212 generated sites, additive only).
**Tested and confirmed it works:** I added a regression test that serves
`{"count":1,"virtualmachine":[]}` and calls `GetVirtualMachinesMetricID`. On
current `main` it reproduces the exact panic from this issue —
```
GetVirtualMachinesMetricID panicked instead of returning an error: runtime
error: index out of range [0] with length 0
```
— and with the guard it returns a clean error instead. `go build ./...` and
the test are both green.
cc @Pearl1594
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]