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 IndexError when there are no suggestions #189

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

elliotwutingfeng
Copy link
Contributor

When there are no suggestions returned by suggest_product() we get an IndexError from attempting to read the first element of an empty list.

I changed it such that if there are no suggestions, no [Y/n] option will be given; the prompt will only state that the search term is not found and exit immediately.

Before

$ eol julia
Traceback (most recent call last):
  File "/home/tingfeng/miniconda3/bin/eol", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/tingfeng/miniconda3/lib/python3.11/site-packages/norwegianblue/cli.py", line 132, in main
    output = norwegianblue.norwegianblue(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tingfeng/miniconda3/lib/python3.11/site-packages/norwegianblue/__init__.py", line 64, in norwegianblue
    suggestion = suggest_product(product)
                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tingfeng/miniconda3/lib/python3.11/site-packages/norwegianblue/__init__.py", line 107, in suggest_product
    return result[0]
           ~~~~~~^^^
IndexError: list index out of range
$

After

$ eol julia
Product 'julia' not found, run 'eol all' for list.
$

@hugovk hugovk added the changelog: Fixed For any bug fixes label Jan 23, 2024
Copy link
Owner

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good, just one small suggestion about the test.

tests/test_norwegianblue.py Outdated Show resolved Hide resolved
@hugovk
Copy link
Owner

hugovk commented Jan 23, 2024

Hmm, and the other test_norwegianblue_formats failures are also now happening on main, so unrelated to this: https://github.com/hugovk/norwegianblue/actions/runs/7622302693

@elliotwutingfeng
Copy link
Contributor Author

elliotwutingfeng commented Jan 23, 2024

This one prompts for andro and proceeds to handle centos only if answered with "Y". But if answered with "n" it halts at andro

$ eol bootstrap andro centos

This one always halts at julia.

$ eol bootstrap julia centos

@elliotwutingfeng elliotwutingfeng marked this pull request as draft January 23, 2024 08:15
@hugovk
Copy link
Owner

hugovk commented Jan 23, 2024

Hmm, and the other test_norwegianblue_formats failures are also now happening on main, so unrelated to this: hugovk/norwegianblue/actions/runs/7622302693

Fixed in #190, let's update this branch.

Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (27da2ae) 98.98% compared to head (d8be1c0) 98.98%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #189   +/-   ##
=======================================
  Coverage   98.98%   98.98%           
=======================================
  Files           7        7           
  Lines         393      395    +2     
=======================================
+ Hits          389      391    +2     
  Misses          4        4           
Flag Coverage Δ
macos-latest 98.98% <100.00%> (+<0.01%) ⬆️
ubuntu-latest 98.98% <100.00%> (+<0.01%) ⬆️
windows-latest 98.98% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hugovk
Copy link
Owner

hugovk commented Jan 23, 2024

Ready for review?

@elliotwutingfeng elliotwutingfeng marked this pull request as ready for review January 24, 2024 00:19
Copy link
Owner

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Thank you!

@hugovk hugovk merged commit cab4e39 into hugovk:main Jan 24, 2024
31 checks passed
@hugovk hugovk changed the title Fix IndexError when there are no suggestions Fix IndexError when there are no suggestions Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: Fixed For any bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants