diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index 05803dd77..ffbcfc644 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -442,9 +442,8 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None) # Check for SEARCH/REPLACE blocks if line.strip() == HEAD: try: - # if next line after HEAD is DIVIDER, it's a new file - next_line = lines[i + 1] - if next_line.strip() == DIVIDER: + # if next line after HEAD exists and is DIVIDER, it's a new file + if i + 1 < len(lines) and lines[i + 1].strip() == DIVIDER: filename = find_filename(lines[max(0, i - 3) : i], fence, None) else: filename = find_filename(