hugovk / norwegianblue

CLI to show end-of-life dates for a number of products.
https://endoflife.date
MIT License
72 stars 4 forks source link

Fix `IndexError` when there are no suggestions #189

Closed elliotwutingfeng closed 5 months ago

elliotwutingfeng commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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
hugovk commented 5 months ago

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 https://github.com/hugovk/norwegianblue/pull/190, let's update this branch.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #189 +/- ## ======================================= Coverage 98.98% 98.98% ======================================= Files 7 7 Lines 393 395 +2 ======================================= + Hits 389 391 +2 Misses 4 4 ``` | [Flag](https://app.codecov.io/gh/hugovk/norwegianblue/pull/189/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+van+Kemenade) | Coverage Δ | | |---|---|---| | [macos-latest](https://app.codecov.io/gh/hugovk/norwegianblue/pull/189/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+van+Kemenade) | `98.98% <100.00%> (+<0.01%)` | :arrow_up: | | [ubuntu-latest](https://app.codecov.io/gh/hugovk/norwegianblue/pull/189/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+van+Kemenade) | `98.98% <100.00%> (+<0.01%)` | :arrow_up: | | [windows-latest](https://app.codecov.io/gh/hugovk/norwegianblue/pull/189/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+van+Kemenade) | `98.98% <100.00%> (+<0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Hugo+van+Kemenade#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

hugovk commented 5 months ago

Ready for review?