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]

Fix(tools): UnicodeDecode errors in state/submit

Kilian Lieretf17e14a41e97
diff --git a/tools/diff_state/bin/_state_diff_state b/tools/diff_state/bin/_state_diff_state
index 8a583fdb..05a77367 100644
--- a/tools/diff_state/bin/_state_diff_state
+++ b/tools/diff_state/bin/_state_diff_state
@@ -28,7 +28,7 @@ def main() -> None:
cwd=repo_root,
)
- patch = patch_path.read_text()
+ patch = patch_path.read_text(errors="backslashreplace")
state["diff"] = patch.strip()
state_path.write_text(json.dumps(state))
diff --git a/tools/review_on_submit/bin/submit b/tools/review_on_submit/bin/submit
index 16ddc360..2c433b8f 100644
--- a/tools/review_on_submit/bin/submit
+++ b/tools/review_on_submit/bin/submit
@@ -5,6 +5,7 @@ from pathlib import Path
import subprocess
import sys
import os
+import io
from registry import registry
@@ -27,7 +28,7 @@ def main() -> None:
cwd=repo_root,
)
- patch = patch_path.read_text()
+ patch = patch_path.read_text(errors="backslashreplace")
if not args.force and not registry.get("SUBMIT_TRIGGERED_BEFORE"):
message = registry.get("SUBMIT_REVIEW_MESSAGE", "")
@@ -43,4 +44,8 @@ def main() -> None:
if __name__ == "__main__":
+ # There are some super strange "ascii can't decode x" errors when printing to the terminal
+ # that can be solved with setting the default encoding for stdout
+ # (note that python3.6 doesn't have the reconfigure method)
+ sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
main()