Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Enh(tools): use utf-8 with errors=replace

Kilian Lieret368ce556f108
diff --git a/tools/edit_anthropic/bin/str_replace_editor b/tools/edit_anthropic/bin/str_replace_editor
index 3ba9572a..1028d7a8 100644
--- a/tools/edit_anthropic/bin/str_replace_editor
+++ b/tools/edit_anthropic/bin/str_replace_editor
@@ -451,14 +451,15 @@ class EditTool:
def read_file(self, path: Path):
"""Read the content of a file from a given path; raise a ToolError if an error occurs."""
encodings = [
- None,
- "utf-8",
- "latin-1",
+ (None, None),
+ ("utf-8", None),
+ ("latin-1", None),
+ ("utf-8", "replace"),
]
exception = None
- for self._encoding in encodings:
+ for self._encoding, errors in encodings:
try:
- text = path.read_text(encoding=self._encoding)
+ text = path.read_text(encoding=self._encoding, errors=errors)
except UnicodeDecodeError as e:
exception = e
else: