Skip to content

Commit

Permalink
fix: made failed patch messages less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Sep 27, 2024
1 parent bfd1b25 commit 3a408d3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions gptme/tools/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def apply(codeblock: str, content: str) -> str:
f"{re.escape(ORIGINAL)}|{re.escape(DIVIDER)}|{re.escape(UPDATED)}", patch
)
if len(parts) != 4: # pragma: no cover
raise ValueError("invalid patch format", patch)
raise ValueError("invalid patch format")

_, original, modified, _ = parts

Expand All @@ -95,15 +95,14 @@ def apply(codeblock: str, content: str) -> str:
if len(originals) != len(modifieds):
raise ValueError(
"different number of placeholders in original and modified chunks"
f"\n{originals}\n{modifieds}"
)
for orig, mod in zip(originals, modifieds):
if orig == mod:
continue
new_content = new_content.replace(orig, mod)
else:
if original not in new_content: # pragma: no cover
raise ValueError("original chunk not found in file", original)
raise ValueError("original chunk not found in file")
new_content = new_content.replace(original, modified)

if new_content == content: # pragma: no cover
Expand Down

0 comments on commit 3a408d3

Please sign in to comment.