feat: add silent mode to read_text method

This commit is contained in:
Paul Gauthier (aider) 2024-12-05 16:22:44 -08:00
parent a664c3dd47
commit e14c84f2fb

View file

@ -321,8 +321,7 @@ class InputOutput:
self.tool_error(f"{filename}: {e}") self.tool_error(f"{filename}: {e}")
return return
# add silent=False, if true don't output any error messages. SEARCH/REPLACE the entire func. AI! def read_text(self, filename, silent=False):
def read_text(self, filename):
if is_image_file(filename): if is_image_file(filename):
return self.read_image(filename) return self.read_image(filename)
@ -330,15 +329,19 @@ class InputOutput:
with open(str(filename), "r", encoding=self.encoding) as f: with open(str(filename), "r", encoding=self.encoding) as f:
return f.read() return f.read()
except OSError as err: except OSError as err:
if not silent:
self.tool_error(f"{filename}: unable to read: {err}") self.tool_error(f"{filename}: unable to read: {err}")
return return
except FileNotFoundError: except FileNotFoundError:
if not silent:
self.tool_error(f"{filename}: file not found error") self.tool_error(f"{filename}: file not found error")
return return
except IsADirectoryError: except IsADirectoryError:
if not silent:
self.tool_error(f"{filename}: is a directory") self.tool_error(f"{filename}: is a directory")
return return
except UnicodeError as e: except UnicodeError as e:
if not silent:
self.tool_error(f"{filename}: {e}") self.tool_error(f"{filename}: {e}")
self.tool_error("Use --encoding to set the unicode encoding.") self.tool_error("Use --encoding to set the unicode encoding.")
return return