summaryrefslogtreecommitdiff
path: root/lib/hyperstack
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 12:17:32 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 12:17:32 +0300
commit9c370329a3339a7a82258f6f8ed677ba1526e1c5 (patch)
treec2e9b7663b1ffb6ea1eaa294f1c02f359365b629 /lib/hyperstack
parent223b422fbca462c07d3c3771e81dd2100d8e3a60 (diff)
fix(manager): only delete state file when VM deletion is confirmed
Ensure Manager#delete does not wipe the state file on generic/transient API failures. The rescue now checks whether the error message indicates the VM is already gone (404, not_found, does not exist) before removing state. This prevents orphaned billable VMs after exhausted retries or transient network errors.
Diffstat (limited to 'lib/hyperstack')
-rw-r--r--lib/hyperstack/manager.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/hyperstack/manager.rb b/lib/hyperstack/manager.rb
index 2134c92..39b8767 100644
--- a/lib/hyperstack/manager.rb
+++ b/lib/hyperstack/manager.rb
@@ -117,10 +117,14 @@ module HyperstackVM
delete_ssh_known_hosts_file
@state_store.delete unless preserve_state_on_failure
info "VM #{target_vm_id} deleted."
- rescue Error
+ rescue Error => e
raise if preserve_state_on_failure
- @state_store.delete
+ gone = e.message.include?('not_found') ||
+ e.message.include?('does not exist') ||
+ e.message.include?('does not exists') ||
+ e.message.include?('404')
+ @state_store.delete if gone
raise
end