fix(changelog): Prevent IndexError for empty paragraphs#1446
Open
soyamigo wants to merge 2 commits into
Open
Conversation
Author
|
FWIW, ran the CI(manual) workflow in my fork: https://github.com/soyamigo/python-semantic-release/actions/runs/27431762140 Seems to be okay. |
…g template filter
Automatically generated by python-semantic-release
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.
Purpose
Fixes an
IndexErrorcrash inautofit_text_widthwhen a commit body contains whitespace-only lines. When PSR parses such a commit and splits the body into paragraphs, a whitespace-only line produces an emptywordslist after filtering. The subsequentline = words[0]then raisesIndexError: list index out of range, aborting changelog generation entirely.This is the full stacktrace:
Rationale
The
wordslist is already constructed with afilter(None, ...)call to strip empty strings, so an empty result after that filter means the paragraph itself was blank or whitespace-only. The correct behavior is to skip such paragraphs entirely, which is consistent with what the surroundingsplit("\n\n")loop is trying to do — process meaningful paragraph blocks. A simpleif not words: continueguard before accessingwords[0]is the minimal, safe fix.How did you test?
Reproduced the crash locally by running
semantic-release versionagainst a repository containing commits with whitespace-only lines in their bodies (e.g. a line containing only spaces or tabs). Confirmed theIndexErroroccurred before the fix and that changelog generation completed successfully after applying it.Edge cases considered:
strip()handles it upstreamHow to Verify
)semantic-release version- observe theIndexError: list index out of rangecrashsemantic-release versionagain to make sure changelog generates successfullyPR Completion Checklist
Reviewed & followed the Contributor Guidelines
Changes Implemented & Validation pipeline succeeds
Commits follow the Conventional Commits standard
and are separated into the proper commit type and scope (recommended order: test, build, feat/fix, docs)
Appropriate Unit tests added/updated
Appropriate End-to-End tests added/updated
Appropriate Documentation added/updated and syntax validated for sphinx build (see Contributor Guidelines)