Skip to content

Commit

Permalink
refactor: add message about wrong ini encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Artprozew committed Jul 27, 2024
1 parent af415b3 commit 2c19633
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/interaction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ def get_ini_settings(

open(self.ini_file, "w").close()

self.config_parser.read(self.ini_file, "utf-16")
try:
self.config_parser.read(self.ini_file, "utf-16")
except UnicodeError:
raise UnicodeError(
f"Could not open the '{self.ini_file}' file to read.\n"
"The encoding seems to be wrong, it needs to be UTF-16-LE."
)

if not self.config_parser.has_section(section):
if mode == "strict":
Expand Down Expand Up @@ -209,8 +215,15 @@ def handle_backup_configs(self, ini_file: str) -> None:
)
backup_configparser.optionxform = lambda option: option # type: ignore # github.com/python/mypy/issues/5062

self.config_parser.read(self.ini_file, "utf-16")
backup_configparser.read(ini_file, "utf-16")
try:
self.config_parser.read(self.ini_file, "utf-16")
backup_configparser.read(ini_file, "utf-16")
except UnicodeError:
self._logger.warning(
"Could not open ini file to apply the backup.\n"
"The encoding seems to be wrong, it needs to be UTF-16-LE."
)
return

for section in backup_configparser.sections():
if section == "INTERNAL":
Expand Down

0 comments on commit 2c19633

Please sign in to comment.