Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NoMethodError when choosing a too big number from gem uni list #6901

Merged
merged 1 commit into from Aug 20, 2023

Conversation

amatsuda
Copy link
Member

What was the end-user or developer problem that led to this PR?

Executing gem uni somegem and choosing a very big number that is not in the list (e.g. choosing 5 from the gem uni rails list where having only 2 rails version being installed) causes the following error:

ERROR:  While executing gem ... (NoMethodError)
    undefined method `>=' for nil

      elsif index >= 0 && index < list.size

This happens since abacb0c by @nobu where choose_from_list has been changed to return nil index when an out-of-bound number was chosen (it used to simply return the chosen index regardless of the list size), and so this error can be reproduced on either rubygems v3.4.18, v3.4.19, and 3.5.0.dev as of today.

What is your fix for the problem, implemented in this PR?

Just added a nil check before using the index value in Uninstaller#uninstall.

I skipped adding a reproduction test for this case because I couldn't find a good place to write such an integrated combination test of the ui and the command while unit test for each of them exist independently.

Make sure the following tasks are checked

@indirect indirect merged commit 9227402 into rubygems:master Aug 20, 2023
83 checks passed
@amatsuda amatsuda deleted the uni_command_npe_fix branch August 20, 2023 11:26
deivid-rodriguez pushed a commit that referenced this pull request Sep 21, 2023
Fix NoMethodError when choosing a too big number from `gem uni` list

(cherry picked from commit 9227402)
deivid-rodriguez pushed a commit that referenced this pull request Sep 21, 2023
Fix NoMethodError when choosing a too big number from `gem uni` list

(cherry picked from commit 9227402)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants