fix(pkg_auto): guard against IndexError on empty free_form_lines in get_batches() - #4223
Open
mohitjeswani01 wants to merge 1 commit into
Open
Conversation
…et_batches() Signed-off-by: Mohit Jeswani <mohitjeswani74@gmail.com>
There was a problem hiding this comment.
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
whilecondition sofree_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
description
In
pkg_auto/impl/sort_packages_list.py, theget_batches()method accessedfree_form_lines[-1]without checking if the list was non-empty first. When acomment block contained package lines but no preceding free-form lines,
free_form_lineswould be empty and thewhilecondition would raiseIndexError: list index out of range.Fix is a one-word guard added to the
whilecondition: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.pyline 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 andshort-circuitsevaluation 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/directory