Skip to content

Commit a1666e4

Browse files
authored
fix: prevent deletion attempts for non-existent vmID -1 (#38)
Fixes #31. Signed-off-by: Philipp Born <[email protected]>
1 parent 5f6d700 commit a1666e4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/proxmox/goproxmox/api_client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ func (c *APIClient) FindVMResource(ctx context.Context, vmID uint64) (*proxmox.C
138138

139139
// DeleteVM deletes a VM based on the nodeName and vmID.
140140
func (c *APIClient) DeleteVM(ctx context.Context, nodeName string, vmID int64) (*proxmox.Task, error) {
141+
// A vmID can not be lower than 100.
142+
// If the provided vmID is lower (like -1 in issue #31), just error out without calling the API.
143+
if vmID < 100 {
144+
return nil, fmt.Errorf("vm with id %d does not exist", vmID)
145+
}
146+
141147
node, err := c.Node(ctx, nodeName)
142148
if err != nil {
143149
return nil, fmt.Errorf("cannot find node with name %s: %w", nodeName, err)

0 commit comments

Comments
 (0)