From 976d2bfd87c12b89068bcf3ff1f34d5038450d12 Mon Sep 17 00:00:00 2001 From: Nikolay Sedelnikov Date: Fri, 30 Aug 2024 16:21:56 +0200 Subject: [PATCH] fix: handle edge case when next line after HEAD is missing --- aider/coders/editblock_coder.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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(