MCPcopy
hub / github.com/qodo-ai/qodo-cover / read_file

Method read_file

cover_agent/lsp_logic/multilspy/multilspy_utils.py:105–125  ·  view source on GitHub ↗

Reads the file at the given path and returns the contents as a string.

(logger: MultilspyLogger, file_path: str)

Source from the content-addressed store, hash-verified

103
104 @staticmethod
105 def read_file(logger: MultilspyLogger, file_path: str) -> str:
106 """
107 Reads the file at the given path and returns the contents as a string.
108 """
109 encodings = ["utf-8-sig", "utf-16"]
110 try:
111 for encoding in encodings:
112 try:
113 with open(file_path, "r", encoding=encoding) as inp_file:
114 return inp_file.read()
115 except UnicodeError:
116 continue
117 except Exception as exc:
118 logger.log(f"File read '{file_path}' failed: {exc}", logging.ERROR)
119 raise MultilspyException("File read failed.") from None
120 logger.log(
121 f"File read '{file_path}' failed: Unsupported encoding.", logging.ERROR
122 )
123 raise MultilspyException(
124 f"File read '{file_path}' failed: Unsupported encoding."
125 ) from None
126
127 @staticmethod
128 def download_file(logger: MultilspyLogger, url: str, target_path: str) -> None:

Callers 1

open_fileMethod · 0.80

Calls 2

MultilspyExceptionClass · 0.90
logMethod · 0.80

Tested by

no test coverage detected