Skip to content

Commit 0bb8577

Browse files
committed
PR review changes
1 parent 884459a commit 0bb8577

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cognite/extractorutils/configtools/loaders.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,19 @@ def _reload_file(self) -> None:
387387
try:
388388
with open(self.config_path, encoding="utf-8") as stream:
389389
self._config_text = stream.read()
390-
except UnicodeDecodeError as e:
391-
_logger.info(f"Using locale default encoding : {e}")
392-
with open(self.config_path) as stream:
393-
self._config_text = stream.read()
390+
except UnicodeDecodeError:
391+
_logger.warning(
392+
f"Config file '{self.config_path}' is not valid UTF-8. Falling back to system default encoding."
393+
)
394+
try:
395+
with open(self.config_path) as stream:
396+
self._config_text = stream.read()
397+
except Exception as e:
398+
_logger.error(
399+
f"Failed to read '{self.config_path}' with both UTF-8 and system default encoding. "
400+
f"The file may be corrupt or in an unsupported format. Final error: {e}"
401+
)
402+
raise RuntimeError("Unable to read configuration file.") from e
394403

395404
@property
396405
def cognite_client(self) -> CogniteClient | None:

tests/tests_unit/test_configtools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,4 +749,4 @@ def test_configresolver_fallback_encoding(tmp_path: Path, caplog: pytest.LogCapt
749749
assert config.logger.file is not None
750750
assert config.logger.file.path is not None
751751
assert "café" in config.logger.file.path
752-
assert any("Using locale default encoding" in r.message for r in caplog.records)
752+
assert any("Falling back to system default encoding." in r.message for r in caplog.records)

0 commit comments

Comments
 (0)