fix(cleaners): raise clear ValueError when extract pattern is absent - #4450
Open
ayam04 wants to merge 1 commit into
Open
fix(cleaners): raise clear ValueError when extract pattern is absent#4450ayam04 wants to merge 1 commit into
ayam04 wants to merge 1 commit into
Conversation
_get_indexed_match referenced the enumerate loop variable i in the not-found error message, but i is never bound when re.finditer yields zero matches, so extract_text_before/extract_text_after raised an UnboundLocalError instead of the intended ValueError. Track the largest match index explicitly so the no-match path always raises a clear message. Closes Unstructured-IO#4427
Contributor
There was a problem hiding this comment.
No issues found across 2 files
Shadow auto-approve: would auto-approve. auto-approve - clear bug fix with focused diff and relevant tests
Re-trigger cubic
Author
|
Hi @cragwolfe @badGarnet — quick ping on this one: Fixes #4427 ( |
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.
Fixes #4427
_get_indexed_matchreferenced the enumerate loop variableiinside the "not found" error message, butiis never bound whenre.finditeryields zero matches. Soextract_text_before/extract_text_afterraised anUnboundLocalError(crash) instead of the intendedValueErrorwhen the pattern does not occur in the text.Track the largest match index in a dedicated variable initialized to
-1, so the no-match path always raises a clear message: "Result with index 0 was not found. The largest index was -1."Tests added:
test_get_indexed_match_no_match_raises_clear_errortest_extract_text_before_no_match_raises_clear_errorValidation:
python3 -m pytest test_unstructured/cleaners/test_extract.py -q(41 passed),uv run ruff checkclean.