fix: Catch exceptions in find_original_update_blocks

This commit is contained in:
Paul Gauthier (aider) 2024-08-22 06:40:03 -07:00
parent ac5667696c
commit b32fa29ba4

View file

@ -22,25 +22,32 @@ def process_markdown(filename):
content = "\n".join(section.split("\n")[1:]).strip() content = "\n".join(section.split("\n")[1:]).strip()
# Process the content with find_original_update_blocks # Process the content with find_original_update_blocks
blocks = list(find_original_update_blocks(content, DEFAULT_FENCE)) try:
blocks = list(find_original_update_blocks(content, DEFAULT_FENCE))
# Create a dictionary for this section # Create a dictionary for this section
section_result = {"header": header, "blocks": []} section_result = {"header": header, "blocks": []}
for block in blocks: for block in blocks:
if block[0] is None: # This is a shell command block if block[0] is None: # This is a shell command block
section_result["blocks"].append({"type": "shell", "content": block[1]}) section_result["blocks"].append({"type": "shell", "content": block[1]})
else: # This is a SEARCH/REPLACE block else: # This is a SEARCH/REPLACE block
section_result["blocks"].append( section_result["blocks"].append(
{ {
"type": "search_replace", "type": "search_replace",
"filename": block[0], "filename": block[0],
"original": block[1], "original": block[1],
"updated": block[2], "updated": block[2],
} }
) )
results.append(section_result) results.append(section_result)
except ValueError as e:
# If an error occurs, add it to the results for this section
results.append({
"header": header,
"error": str(e)
})
# Output the results as JSON # Output the results as JSON
print(json.dumps(results, indent=4)) print(json.dumps(results, indent=4))