From 6c7b2e9078a261c31ca00a81b59b430f784bef1d Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Tue, 20 May 2025 11:28:31 +0200 Subject: [PATCH] Only use utf-8 encoding for now --- src/multilspy/multilspy_utils.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/multilspy/multilspy_utils.py b/src/multilspy/multilspy_utils.py index 75f023a..9dcfd8a 100644 --- a/src/multilspy/multilspy_utils.py +++ b/src/multilspy/multilspy_utils.py @@ -128,22 +128,12 @@ class FileUtils: if not os.path.exists(file_path): logger.log(f"File read '{file_path}' failed: File does not exist.", logging.ERROR) raise MultilspyException(f"File read '{file_path}' failed: File does not exist.") - encodings = ["utf-8-sig", "utf-16", "utf-8", "latin-1"] try: - for encoding in encodings: - try: - with open(file_path, "r", encoding=encoding) as inp_file: - return inp_file.read() - except UnicodeError: - continue - # Try system default encoding as a last resort - with open(file_path, "r") as inp_file: + with open(file_path, "r", encoding="utf-8") as inp_file: return inp_file.read() except Exception as exc: - logger.log(f"File read '{file_path}' failed: {exc}", logging.ERROR) + logger.log(f"File read '{file_path}' failed to read with encoding 'utf-8': {exc}", logging.ERROR) raise MultilspyException("File read failed.") from None - logger.log(f"File read '{file_path}' failed: Unsupported encoding.", logging.ERROR) - raise MultilspyException(f"File read '{file_path}' failed: Unsupported encoding.") from None @staticmethod def download_file(logger: MultilspyLogger, url: str, target_path: str) -> None: