Skip to content

The agent engineering platform.

cli[patch]: unicode issue (#14672)

Erick Friisc5250f12c207
diff --git a/libs/cli/langchain_cli/utils/find_replace.py b/libs/cli/langchain_cli/utils/find_replace.py
index 7053a9cdda..cfea68d3df 100644
--- a/libs/cli/langchain_cli/utils/find_replace.py
+++ b/libs/cli/langchain_cli/utils/find_replace.py
@@ -14,7 +14,14 @@ def find_and_replace(source: str, replacements: Dict[str, str]) -> str:
def replace_file(source: Path, replacements: Dict[str, str]) -> None:
- source.write_text(find_and_replace(source.read_text(), replacements))
+ try:
+ content = source.read_text()
+ except UnicodeDecodeError:
+ # binary file
+ return
+ new_content = find_and_replace(content, replacements)
+ if new_content != content:
+ source.write_text(new_content)
def replace_glob(parent: Path, glob: str, replacements: Dict[str, str]) -> None: