Skip to content

Fix nil provider crash when purging unconfigured EC2 resources#700

Open
smahima27 wants to merge 1 commit intomainfrom
fix-ec2-nil-provider
Open

Fix nil provider crash when purging unconfigured EC2 resources#700
smahima27 wants to merge 1 commit intomainfrom
fix-ec2-nil-provider

Conversation

@smahima27
Copy link
Contributor

Problem

When a provider (e.g., EC2) is listed under :providers in config but is not initialized in $providers (missing credentials, not fully configured, etc.), purge_vms_and_resources crashes with:

[!] failed while purging provider ec2 VMs and folders with an error: undefined method `provider_config' for nil:NilClass

This error was observed in production logs on startup when purge_unconfigured_resources runs for the EC2 provider.

Fix

Add a nil guard in purge_vms_and_resources: if $providers[provider_name] is nil, log and return early instead of raising NoMethodError.

unless provider
  $logger.log('d', "[!] [purge] Skipping provider '#{provider_name}': not initialized")
  return
end

Testing

  • Existing specs pass
  • Reproduces: configure an EC2 provider in :providers without initializing it in $providers; before this fix it crashes, after this fix it logs and skips cleanly

Add nil guard in purge_vms_and_resources: when a provider is listed in
config but not initialized in $providers, log and return early instead
of crashing with: undefined method provider_config for nil:NilClass
@smahima27 smahima27 requested a review from a team as a code owner March 23, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant