Skip to content

Fix nil crash in delete_unused_runtimes when a required runtime is missing#63

Merged
nekrich merged 4 commits into
MacPaw:mainfrom
afurm:fix/delete-unused-runtimes-nil-crash
Mar 5, 2026
Merged

Fix nil crash in delete_unused_runtimes when a required runtime is missing#63
nekrich merged 4 commits into
MacPaw:mainfrom
afurm:fix/delete-unused-runtimes-nil-crash

Conversation

@afurm

@afurm afurm commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a crash in RuntimeHelper#delete_unused_runtimes that could happen when at least one required runtime is still missing.

Problem

delete_unused_runtimes built needed_simctl_runtimes with map.
If a required runtime had no match, simctl_runtime_matching_needed_runtime? returned nil.
Later, the code called needed_simctl_runtime.identifier, which raised:

NoMethodError: undefined method 'identifier' for nil

Changes

  • Updated delete_unused_runtimes to use filter_map instead of map, so unmatched (nil) runtimes are excluded safely.
  • Added a regression spec for the mixed case:
    • one required runtime matches
    • one required runtime is missing
    • method does not crash
    • unused runtime deletion still proceeds

Validation

  • bundle exec rspec
    • Result: 44 examples, 0 failures
  • bundle exec rubocop lib/.../runtime_helper.rb spec/.../runtime_helper_spec.rb
    • Result: no offenses

Risk

Low.
The change is small, isolated, and covered by a regression test.

@afurm afurm requested a review from nekrich as a code owner March 4, 2026 15:05

@nekrich nekrich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Thanks for the PR.

@nekrich nekrich enabled auto-merge (squash) March 4, 2026 17:06
@nekrich nekrich disabled auto-merge March 5, 2026 09:04
@nekrich nekrich merged commit 51bb163 into MacPaw:main Mar 5, 2026
4 checks passed
@afurm afurm deleted the fix/delete-unused-runtimes-nil-crash branch March 5, 2026 09:35
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.

3 participants