Skip to content

fix(pkg_auto): guard against IndexError on empty free_form_lines in get_batches() - #4223

Open
mohitjeswani01 wants to merge 1 commit into
flatcar:mainfrom
mohitjeswani01:fix/pkg-auto-indexerror-free-form-lines
Open

fix(pkg_auto): guard against IndexError on empty free_form_lines in get_batches()#4223
mohitjeswani01 wants to merge 1 commit into
flatcar:mainfrom
mohitjeswani01:fix/pkg-auto-indexerror-free-form-lines

Conversation

@mohitjeswani01

@mohitjeswani01 mohitjeswani01 commented Aug 19, 2026

Copy link
Copy Markdown

description

In pkg_auto/impl/sort_packages_list.py, the get_batches() method accessed
free_form_lines[-1] without checking if the list was non-empty first. When a
comment block contained package lines but no preceding free-form lines,
free_form_lines would be empty and the while condition would raise
IndexError: list index out of range.

Fix is a one-word guard added to the while condition:
while free_form_lines and not free_form_lines[-1]:

Fixes flatcar/Flatcar#2342.

How to use

Review the single-line change in pkg_auto/impl/sort_packages_list.py line 109.
No setup required — the fix is self-evident from the diff.

Testing done

Verified the fix by code reading. The guard free_form_lines and short-circuits
evaluation when the list is empty, preventing the IndexError.

python -m py_compile pkg_auto/impl/sort_packages_list.py

Output: Exit code 0 (no syntax errors)

  • Changelog entries added in the respective changelog/ directory
  • Inspected CI output for image differences

…et_batches()

Signed-off-by: Mohit Jeswani <mohitjeswani74@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Guards Reader.get_batches() against an IndexError when free_form_lines is empty while trimming trailing blank lines from comment batches.

Changes:

  • Add a short-circuit check to the while condition so free_form_lines[-1] is only evaluated when the list is non-empty.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg_auto/impl/sort_packages_list.py
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.

bug(pkg_auto): IndexError on empty free_form_lines in get_batches()

2 participants